diff options
author | Alex Lorenz <arphaman@gmail.com> | 2016-12-07 10:24:44 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2016-12-07 10:24:44 +0000 |
commit | e151f010deab7417abf663fb1c8ff841539903e7 (patch) | |
tree | a6d9821dbfb097e82234e4f8227c749f3b7bf72e | |
parent | 59336a0a45c64bef27adf2476274466134693723 (diff) | |
download | bcm5719-llvm-e151f010deab7417abf663fb1c8ff841539903e7.tar.gz bcm5719-llvm-e151f010deab7417abf663fb1c8ff841539903e7.zip |
[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
llvm-svn: 288893
-rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCXXScopeSpec.cpp | 5 | ||||
-rw-r--r-- | clang/test/SemaObjCXX/crash.mm | 35 |
3 files changed, 48 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index d15e41ddc1c..ea7ab267701 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -5264,6 +5264,14 @@ void Parser::ParseDirectDeclarator(Declarator &D) { // 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: diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp index 6c7d8133173..d8971c0d37e 100644 --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -1001,6 +1001,11 @@ void Sema::RestoreNestedNameSpecifierAnnotation(void *AnnotationPtr, 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 diff --git a/clang/test/SemaObjCXX/crash.mm b/clang/test/SemaObjCXX/crash.mm index 19cf3099828..a9754b7bc54 100644 --- a/clang/test/SemaObjCXX/crash.mm +++ b/clang/test/SemaObjCXX/crash.mm @@ -25,3 +25,38 @@ template<typename...Ts> void f(Ts); // expected-error {{unexpanded}} // 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 |