Author: arphaman Date: Wed Dec 7 04:24:44 2016 New Revision: 288893 URL: http://llvm.org/viewvc/llvm-project?rev=288893&view=rev Log: [ObjC++] Don't enter a C++ declarator scope when the current context is an Objective-C declaration
This commit ensures that Sema won't enter a C++ declarator scope when the current context is an Objective-C declaration. This prevents an assertion failure in EnterDeclaratorContext that's used to ensure that current context will be restored correctly after exiting the declarator context. rdar://20560175 Differential Revision: https://reviews.llvm.org/D26922 Modified: cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp cfe/trunk/test/SemaObjCXX/crash.mm Modified: cfe/trunk/lib/Parse/ParseDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=288893&r1=288892&r2=288893&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) +++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Dec 7 04:24:44 2016 @@ -5264,6 +5264,14 @@ void Parser::ParseDirectDeclarator(Decla // Change the declaration context for name lookup, until this function // is exited (and the declarator has been parsed). DeclScopeObj.EnterDeclaratorScope(); + else if (getObjCDeclContext()) { + // Ensure that we don't interpret the next token as an identifier when + // dealing with declarations in an Objective-C container. + D.SetIdentifier(nullptr, Tok.getLocation()); + D.setInvalidType(true); + ConsumeToken(); + goto PastIdentifier; + } } // C++0x [dcl.fct]p14: Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=288893&r1=288892&r2=288893&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original) +++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Wed Dec 7 04:24:44 2016 @@ -1001,6 +1001,11 @@ void Sema::RestoreNestedNameSpecifierAnn bool Sema::ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) { assert(SS.isSet() && "Parser passed invalid CXXScopeSpec."); + // Don't enter a declarator context when the current context is an Objective-C + // declaration. + if (isa<ObjCContainerDecl>(CurContext) || isa<ObjCMethodDecl>(CurContext)) + return false; + NestedNameSpecifier *Qualifier = SS.getScopeRep(); // There are only two places a well-formed program may qualify a Modified: cfe/trunk/test/SemaObjCXX/crash.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/crash.mm?rev=288893&r1=288892&r2=288893&view=diff ============================================================================== --- cfe/trunk/test/SemaObjCXX/crash.mm (original) +++ cfe/trunk/test/SemaObjCXX/crash.mm Wed Dec 7 04:24:44 2016 @@ -25,3 +25,38 @@ template<typename...Ts> void f(Ts); // e // expected-warning@-2 {{variadic templates are a C++11 extension}} #endif @end + +// rdar://20560175 + +struct OuterType { + typedef int InnerType; +}; + +namespace ns { + typedef int InnerType; +}; + +@protocol InvalidProperties + +@property (nonatomic) (OuterType::InnerType) invalidTypeParens; +// expected-error@-1 {{type name requires a specifier or qualifier}} +// expected-error@-2 {{property requires fields to be named}} +// expected-error@-3 {{expected ';' at end of declaration list}} +// expected-error@-4 {{C++ requires a type specifier for all declarations}} +// expected-error@-5 {{cannot declare variable inside @interface or @protocol}} + +@property (nonatomic) (ns::InnerType) invalidTypeParens2; +// expected-error@-1 {{type name requires a specifier or qualifier}} +// expected-error@-2 {{property requires fields to be named}} +// expected-error@-3 {{expected ';' at end of declaration list}} +// expected-error@-4 {{C++ requires a type specifier for all declarations}} +// expected-error@-5 {{cannot declare variable inside @interface or @protocol}} + +@property (nonatomic) int OuterType::InnerType; // expected-error {{property requires fields to be named}} + +@property (nonatomic) int OuterType::InnerType foo; // expected-error {{property requires fields to be named}} +// expected-error@-1 {{expected ';' at end of declaration list}} +// expected-error@-2 {{C++ requires a type specifier for all declarations}} +// expected-error@-3 {{cannot declare variable inside @interface or @protocol}} + +@end _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits