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

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 21 10:18:44 PST 2016


arphaman created this revision.
arphaman added reviewers: manmanren, ahatanak.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch ensures that Sema won't enter a C++ declarator context 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. I think that this approach is reasonable as AFAIK we don't need to use the C++ declarator contexts directly in Objective-C declarations, since they're mostly used to define out of line variables declared in classes or namespaces which shouldn't be done inside an Objective-C declaration.


Repository:
  rL LLVM

https://reviews.llvm.org/D26922

Files:
  lib/Sema/SemaCXXScopeSpec.cpp
  test/SemaObjCXX/crash.mm


Index: test/SemaObjCXX/crash.mm
===================================================================
--- test/SemaObjCXX/crash.mm
+++ test/SemaObjCXX/crash.mm
@@ -25,3 +25,17 @@
 // expected-warning at -2 {{variadic templates are a C++11 extension}}
 #endif
 @end
+
+// rdar://20560175
+
+struct OuterType {
+  typedef int InnerType;
+};
+
+ at protocol InvalidProperty
+ at property (nonatomic) (OuterType::InnerType) invalidTypeParens;
+// expected-error at -1 {{type name requires a specifier or qualifier}}
+// expected-error at -2 {{expected ';' at end of declaration list}}
+// expected-error at -3 {{C++ requires a type specifier for all declarations}}
+// expected-error at -4 {{cannot declare variable inside @interface or @protocol}}
+ at end
Index: lib/Sema/SemaCXXScopeSpec.cpp
===================================================================
--- lib/Sema/SemaCXXScopeSpec.cpp
+++ lib/Sema/SemaCXXScopeSpec.cpp
@@ -1054,7 +1054,12 @@
   // it is a complete declaration context.
   if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
     return true;
-    
+
+  // Don't enter a declarator context when the current context is an Objective-C
+  // declaration as we might no be able to restore it when exiting the scope.
+  if (isa<ObjCContainerDecl>(CurContext) || isa<ObjCMethodDecl>(CurContext))
+    return true;
+
   EnterDeclaratorContext(S, DC);
 
   // Rebuild the nested name specifier for the new scope.


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


More information about the cfe-commits mailing list