]> granicus.if.org Git - clang/commitdiff
Implement the suggested resolution of WG21 N3307 issue 19: When determining whether...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 5 Sep 2011 02:13:09 +0000 (02:13 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 5 Sep 2011 02:13:09 +0000 (02:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139111 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclCXX.cpp
test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp
test/SemaCXX/aggregate-initialization.cpp

index be529f85a6a3a7c06915c31f05c03ffb4a6543da..1821ba8a6aed436515a016ee0c3f8ad5953bdad6 100644 (file)
@@ -503,18 +503,18 @@ NotASpecialMember:;
     // Note that we have a user-declared constructor.
     data().UserDeclaredConstructor = true;
 
-    // FIXME: Under C++0x, /only/ special member functions may be user-provided.
-    //        This is probably a defect.
-    bool UserProvided = false;
+    // Technically, "user-provided" is only defined for special member
+    // functions, but the intent of the standard is clearly that it should apply
+    // to all functions.
+    bool UserProvided = Constructor->isUserProvided();
 
     // C++0x [class.ctor]p5:
     //   A default constructor is trivial if it is not user-provided [...]
     if (Constructor->isDefaultConstructor()) {
       data().DeclaredDefaultConstructor = true;
-      if (Constructor->isUserProvided()) {
+      if (UserProvided) {
         data().HasTrivialDefaultConstructor = false;
         data().UserProvidedDefaultConstructor = true;
-        UserProvided = true;
       }
     }
 
@@ -528,10 +528,8 @@ NotASpecialMember:;
         // C++0x [class.copy]p13:
         //   A copy/move constructor for class X is trivial if it is not
         //   user-provided [...]
-        if (Constructor->isUserProvided()) {
+        if (UserProvided)
           data().HasTrivialCopyConstructor = false;
-          UserProvided = true;
-        }
       } else if (Constructor->isMoveConstructor()) {
         data().UserDeclaredMoveConstructor = true;
         data().DeclaredMoveConstructor = true;
@@ -539,10 +537,8 @@ NotASpecialMember:;
         // C++0x [class.copy]p13:
         //   A copy/move constructor for class X is trivial if it is not
         //   user-provided [...]
-        if (Constructor->isUserProvided()) {
+        if (UserProvided)
           data().HasTrivialMoveConstructor = false;
-          UserProvided = true;
-        }
       }
     }
     if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor()) {
index 9b92340fa457d456f0550bb64ca61b8872dee981..146313392aebd9de65419955de304cec04562aa4 100644 (file)
@@ -18,11 +18,10 @@ struct NonAggr1a {
   NonAggr1a(int, int);
   int k;
 };
-// In C++03, this is {{non-aggregate type 'NonAggr1a'}}.
 // In C++0x, 'user-provided' is only defined for special member functions, so
-// this type is considered to be an aggregate. This is probably a langauge
-// defect.
-NonAggr1a na1a = { 42 };
+// this type is considered to be an aggregate. This is considered to be
+// a language defect.
+NonAggr1a na1a = { 42 }; // expected-error {{non-aggregate type 'NonAggr1a'}}
 
 struct NonAggr1b {
   NonAggr1b(const NonAggr1b &);
index b9e69b00b7fefacdb9e15899af28c3a3534bb56e..90d0ead92049f92e594716a9b9ba2d1dfdb66bd6 100644 (file)
@@ -2,8 +2,8 @@
 
 // Verify that we can't initialize non-aggregates with an initializer
 // list.
-// FIXME: Note that due to a (likely) standard bug, this is technically an
-//        aggregate.
+// Note that due to a (likely) standard bug, this is technically an aggregate,
+// but we do not treat it as one.
 struct NonAggr1 {
   NonAggr1(int) { }
 
@@ -24,7 +24,7 @@ struct NonAggr4 {
   virtual void f();
 };
 
-NonAggr1 na1 = { 17 };
+NonAggr1 na1 = { 17 }; // expected-error{{non-aggregate type 'NonAggr1' cannot be initialized with an initializer list}}
 NonAggr2 na2 = { 17 }; // expected-error{{non-aggregate type 'NonAggr2' cannot be initialized with an initializer list}}
 NonAggr3 na3 = { 17 }; // expected-error{{non-aggregate type 'NonAggr3' cannot be initialized with an initializer list}}
 NonAggr4 na4 = { 17 }; // expected-error{{non-aggregate type 'NonAggr4' cannot be initialized with an initializer list}}