This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Don't perform aggregate initialization for types with explicit constructors
ClosedPublic

Authored by EricWF on Oct 16 2016, 2:57 AM.

Details

Summary

The C++17 rules for aggregate initialization changed to disallow types with explicit constructors [dcl.init.aggr]p1. This patch implements that new rule.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 74786.Oct 16 2016, 2:57 AM
EricWF retitled this revision from to [Sema] Don't perform aggregate initialization for types with explicit constructors.
EricWF updated this object.
EricWF added a reviewer: rsmith.
EricWF added a subscriber: cfe-commits.
rsmith edited edge metadata.Oct 16 2016, 10:26 AM

Please also add a test to test/CXX/drs/dr15xx.cpp for core issue 1518, which this paper was resolving.

lib/AST/DeclCXX.cpp
564

Do we correctly handle the "or inherited" part? I'd also like to find out whether core intended for this issue to be treated as a DR or not (if so, this should apply all the way back to C++11).

EricWF updated this revision to Diff 76095.Oct 27 2016, 1:59 PM
EricWF edited edge metadata.
  • Disallow classes with inherited constructors
  • Add tests under test/CXX/drs/dr15xx.cpp

I still only implemented this change in C++1z, please let me know if you want me to backport the DR.

@rsmith ping. This is kind-of blocking making libc++'s tag types not constructible from {}.

rsmith added inline comments.Nov 17 2016, 11:37 AM
lib/AST/DeclCXX.cpp
564

According to the current issues list, this issue is in DRWP status, so this change should be applied retroactively to C++11 and C++14 as well.

EricWF updated this revision to Diff 78410.Nov 17 2016, 1:23 PM

OK, I've applied the fix to C++11 and C++14. Although the inheriting-constructor part still only matters in C++1z since it requires having base classes.

I also fixed aggregate initialization for types with non-aggregate base classes. For example:

struct A { A(int); };
struct B : A {};
B b = {42}; // OK in C++1z
EricWF updated this revision to Diff 78459.Nov 17 2016, 7:36 PM

Add tests that explicit default constructors are still allowed outside of copy-initialization.

rsmith accepted this revision.Nov 26 2016, 12:05 PM
rsmith edited edge metadata.
This revision is now accepted and ready to land.Nov 26 2016, 12:05 PM
EricWF closed this revision.Dec 2 2016, 5:36 PM