As the title says, this makes following code compile:
template<typename> struct Foo {}; Foo() -> Foo<void>; Foo f; // ok
Thanks Nicolas Lesser for coining the fix.
Differential D38216
[C++17] Fix class template argument deduction for default constructors without an initializer Rakete1111 on Sep 23 2017, 12:22 PM. Authored by
Details
As the title says, this makes following code compile: template<typename> struct Foo {}; Foo() -> Foo<void>; Foo f; // ok Thanks Nicolas Lesser for coining the fix.
Diff Detail Event TimelineComment Actions The standard hasn't allowed deducing any placeholder type without an initializer (10.1.7.4.1 [dcl.type.auto.deduct]/2) yet. It's unclear to me what extern A x; wants to archive. Usually when people writing extern then expect an initializer to appear somewhere else, but with this declaration, defining A x = ...; later may fail by resolving to a different type, which feels... interesting. Comment Actions @lichray Isn't [dcl.type.auto.deduct] only for auto and decltype(auto)? Class template argument deduction is in [dcl.type.class.deduct], which doesn't seem to disallow declarations without an initializer. About that extern business, yes that's indeed counter intuitive and weird. Couldn't find anything in the standard prohibiting this though, but I'm not so good at that either. Comment Actions Sorry, reasoned on a confusingly similar part... Here is
So deducing from default initialization is indeed allowed, but extern Comment Actions That's almost right, but not all extern declarations are disallowed. (An extern declaration is still a defining declaration if it has an initializer.)
Comment Actions Made DeduceInits empty instead of a workaround somewhere else. Is it still ok, @rsmith ? Comment Actions Per [dcl.type.class.deduct]p1, only the initializing declaration of a variable can use a placeholder type. The existing diagnostic was correct in many of the modified cases.
Comment Actions LGTM
|
Please put this ?: expression into the declaration of DeduceInits instead of here. (We should build an empty list instead of a list of one null pointer when there is no init.)