From: David Blaikie Date: Tue, 14 Feb 2012 09:00:46 +0000 (+0000) Subject: Fix crash-on-invalid for 'operator int[]()' in C++11. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3164c14cadbb09a05ba811602221e9156077cf44;p=clang Fix crash-on-invalid for 'operator int[]()' in C++11. Signed off by Richard Smith. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150464 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index cc0cf15e73..6213824cae 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1989,11 +1989,12 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, // 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) { diff --git a/test/SemaCXX/member-init.cpp b/test/SemaCXX/member-init.cpp index 819c8d13db..c93c85bbf8 100644 --- a/test/SemaCXX/member-init.cpp +++ b/test/SemaCXX/member-init.cpp @@ -29,6 +29,9 @@ const int C = 0, D = 0; struct S { int as[] = { decltype(x)::B(0) }; // expected-error {{array bound cannot be deduced from an in-class initializer}} T 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); };