[PATCH] D26922: [ObjC++] Don't enter a C++ declarator context when the current context is an Objective-C declaration

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 7 02:34:58 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL288893: [ObjC++] Don't enter a C++ declarator scope when the current context is (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D26922?vs=79722&id=80556#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26922

Files:
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
  cfe/trunk/test/SemaObjCXX/crash.mm


Index: cfe/trunk/test/SemaObjCXX/crash.mm
===================================================================
--- cfe/trunk/test/SemaObjCXX/crash.mm
+++ cfe/trunk/test/SemaObjCXX/crash.mm
@@ -25,3 +25,38 @@
 // expected-warning at -2 {{variadic templates are a C++11 extension}}
 #endif
 @end
+
+// rdar://20560175
+
+struct OuterType {
+  typedef int InnerType;
+};
+
+namespace ns {
+  typedef int InnerType;
+};
+
+ at protocol InvalidProperties
+
+ at property (nonatomic) (OuterType::InnerType) invalidTypeParens;
+// expected-error at -1 {{type name requires a specifier or qualifier}}
+// expected-error at -2 {{property requires fields to be named}}
+// expected-error at -3 {{expected ';' at end of declaration list}}
+// expected-error at -4 {{C++ requires a type specifier for all declarations}}
+// expected-error at -5 {{cannot declare variable inside @interface or @protocol}}
+
+ at property (nonatomic) (ns::InnerType) invalidTypeParens2;
+// expected-error at -1 {{type name requires a specifier or qualifier}}
+// expected-error at -2 {{property requires fields to be named}}
+// expected-error at -3 {{expected ';' at end of declaration list}}
+// expected-error at -4 {{C++ requires a type specifier for all declarations}}
+// expected-error at -5 {{cannot declare variable inside @interface or @protocol}}
+
+ at property (nonatomic) int OuterType::InnerType; // expected-error {{property requires fields to be named}}
+
+ at property (nonatomic) int OuterType::InnerType foo; // expected-error {{property requires fields to be named}}
+// expected-error at -1 {{expected ';' at end of declaration list}}
+// expected-error at -2 {{C++ requires a type specifier for all declarations}}
+// expected-error at -3 {{cannot declare variable inside @interface or @protocol}}
+
+ at end
Index: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
@@ -1001,6 +1001,11 @@
 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
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -5264,6 +5264,14 @@
         // 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26922.80556.patch
Type: text/x-patch
Size: 3201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161207/e5d2e44f/attachment.bin>


More information about the cfe-commits mailing list