Skip to content

Conversation

@kennykerr
Copy link
Collaborator

Fixes #413

@oldnewthing
Copy link
Member

oldnewthing commented Nov 15, 2019

0-parameter and N-parameter constructors can also be converting constructors. I think we should allow the the 0-parameter converting constructor, and I'm not sure about whether we should allow the N-parameter one.

I'm assuming we are leaving the 1-parameter nullptr conversion constructor enabled.

struct C {
  C();
  C(std::nullptr_t);
  C(Int32);
  C(Int32, Int32);
};

void F(C c);
Statement Prior to this change After this change Desired?
F({}); Allowed Allowed Probably
F(nullptr); Allowed Allowed(?) Yes
F(42); Allowed Disallowed Probably not
F({ 42, 96 }); Allowed Allowed Unclear
C c; Allowed Allowed Yes
C c{nullptr}; Allowed Allowed(?) Yes
C c(42); Allowed Allowed Yes
C c(42, 96); Allowed Allowed Yes
C c = {}; Allowed Allowed Probably
C c = nullptr; Allowed Allowed(?) Probably
C c = 42; Allowed Disallowed Probably not
C c = { 42, 96 }; Allowed Allowed Unclear

@kennykerr
Copy link
Collaborator Author

kennykerr commented Nov 15, 2019

@oldnewthing yes, I'm not planning on changing anything about initialization in general and rather leaving the C++ language defaults as is. The nullptr_t is not explicit as doing so would be a bigger breaking change and the value of taking that on is questionable. Having single-parameter constructors explicit solves the chief usability/pit-of-failure issue here.

@kennykerr kennykerr merged commit 6218c03 into master Nov 15, 2019
@kennykerr kennykerr deleted the kennykerr-explicit branch November 15, 2019 18:42
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

Successfully merging this pull request may close these issues.

Generated C++/WinRT constructors should be marked explicit

4 participants