Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C.46: Recommend marking nonexplicit single-argument constructors with explicit(false) #2216

Closed
LocalSpook opened this issue Sep 9, 2024 · 1 comment
Assignees

Comments

@LocalSpook
Copy link

LocalSpook commented Sep 9, 2024

C.46 currently just says that nonexplicit single-argument constructors are rarely justified and suggests warning for any that aren't on some whitelist. Then the GSL section recommends making intent explicit with the nonstandard attribute [[implicit]].

Since C++20 introduced conditionally explicit specifiers, we can express this portably with explicit(false):

class Complex {
public:
    explicit(false) Complex(double d);   // OK: we want a conversion from d to {d, 0}
    // ...
};

Complex z = 10.7;   // unsurprising conversion

(I first saw this in P3094's sample implementation of basic_fixed_string.)

@hsutter
Copy link
Contributor

hsutter commented Sep 26, 2024

Editors call: Thanks! We understand the motivation but we don't think making such declarations longer has significant benefits.

@hsutter hsutter closed this as completed Sep 26, 2024
@hsutter hsutter self-assigned this Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants