[PATCH] D25654: [Sema] Don't perform aggregate initialization for types with explicit constructors

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 16 02:57:22 PDT 2016


EricWF created this revision.
EricWF added a reviewer: rsmith.
EricWF added a subscriber: cfe-commits.

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


https://reviews.llvm.org/D25654

Files:
  lib/AST/DeclCXX.cpp
  test/SemaCXX/aggregate-initialization.cpp


Index: test/SemaCXX/aggregate-initialization.cpp
===================================================================
--- test/SemaCXX/aggregate-initialization.cpp
+++ test/SemaCXX/aggregate-initialization.cpp
@@ -146,3 +146,12 @@
   // expected-error at -5 {{protected constructor}}
   // expected-note at -30 {{here}}
 }
+
+namespace diff_cpp1z_dcl_init_aggr_example {
+  struct ExplicitDefault { explicit ExplicitDefault() = default; };
+  ExplicitDefault d = {};
+#if __cplusplus > 201402L
+  // expected-error at -2 {{explicit in copy-initialization}}
+  // expected-note at -4 {{here}}
+#endif
+}
Index: lib/AST/DeclCXX.cpp
===================================================================
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -560,6 +560,10 @@
             ? Constructor->isUserProvided()
             : !Constructor->isImplicit())
       data().Aggregate = false;
+    // C++1z [dcl.init.aggr]p1:
+    //  - no user-provided, explicit, or inherited constructors,
+    if (getASTContext().getLangOpts().CPlusPlus1z && Constructor->isExplicit())
+      data().Aggregate = false;
   }
 
   // Handle destructors.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25654.74786.patch
Type: text/x-patch
Size: 1121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161016/5911c04c/attachment.bin>


More information about the cfe-commits mailing list