[cfe-commits] r150464 - in /cfe/trunk: lib/Parse/ParseDeclCXX.cpp test/SemaCXX/member-init.cpp

David Blaikie dblaikie at gmail.com
Tue Feb 14 01:00:47 PST 2012


Author: dblaikie
Date: Tue Feb 14 03:00:46 2012
New Revision: 150464

URL: http://llvm.org/viewvc/llvm-project?rev=150464&view=rev
Log:
Fix crash-on-invalid for 'operator int[]()' in C++11.

Signed off by Richard Smith.

Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/SemaCXX/member-init.cpp

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=150464&r1=150463&r2=150464&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Feb 14 03:00:46 2012
@@ -1989,11 +1989,12 @@
         // declarator is followed by an initializer. 
         //
         // A brace-or-equal-initializer for a member-declarator is not an
-        // initializer in the gramamr, so this is ill-formed.
+        // initializer in the grammar, so this is ill-formed.
         Diag(Tok, diag::err_incomplete_array_member_init);
         SkipUntil(tok::comma, true, true);
-        // Avoid later warnings about a class member of incomplete type.
-        ThisDecl->setInvalidDecl();
+        if (ThisDecl)
+          // Avoid later warnings about a class member of incomplete type.
+          ThisDecl->setInvalidDecl();
       } else
         ParseCXXNonStaticMemberInitializer(ThisDecl);
     } else if (HasInitializer) {

Modified: cfe/trunk/test/SemaCXX/member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/member-init.cpp?rev=150464&r1=150463&r2=150464&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/member-init.cpp (original)
+++ cfe/trunk/test/SemaCXX/member-init.cpp Tue Feb 14 03:00:46 2012
@@ -29,6 +29,9 @@
 struct S {
   int as[] = { decltype(x)::B<C, D>(0) }; // expected-error {{array bound cannot be deduced from an in-class initializer}}
   T<sizeof(as) / sizeof(int)> x; // expected-error {{requires a type specifier}}
+  // test that we handle invalid array bound deductions without crashing when the declarator name is itself invalid
+  operator int[](){}; // expected-error {{'operator int' cannot be the name of a variable or data member}} \
+                      // expected-error {{array bound cannot be deduced from an in-class initializer}}
 };
 
 struct ThrowCtor { ThrowCtor(int) noexcept(false); };





More information about the cfe-commits mailing list