r197000 - When performing a delayed access check, use the surrounding lexical context for

Richard Smith richard-llvm at metafoo.co.uk
Tue Dec 10 19:35:27 PST 2013


Author: rsmith
Date: Tue Dec 10 21:35:27 2013
New Revision: 197000

URL: http://llvm.org/viewvc/llvm-project?rev=197000&view=rev
Log:
When performing a delayed access check, use the surrounding lexical context for
any local extern declaration, not just a local extern function.

Modified:
    cfe/trunk/lib/Sema/SemaAccess.cpp
    cfe/trunk/test/SemaCXX/access.cpp

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=197000&r1=196999&r2=197000&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Tue Dec 10 21:35:27 2013
@@ -1482,11 +1482,10 @@ void Sema::HandleDelayedAccessCheck(Dela
   // However, this does not apply to local extern declarations.
 
   DeclContext *DC = D->getDeclContext();
-  if (FunctionDecl *FN = dyn_cast<FunctionDecl>(D)) {
-    if (D->getLexicalDeclContext()->isFunctionOrMethod())
-      DC = D->getLexicalDeclContext();
-    else
-      DC = FN;
+  if (D->isLocalExternDecl()) {
+    DC = D->getLexicalDeclContext();
+  } else if (FunctionDecl *FN = dyn_cast<FunctionDecl>(D)) {
+    DC = FN;
   } else if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) {
     DC = cast<DeclContext>(TD->getTemplatedDecl());
   }

Modified: cfe/trunk/test/SemaCXX/access.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/access.cpp?rev=197000&r1=196999&r2=197000&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/access.cpp (original)
+++ cfe/trunk/test/SemaCXX/access.cpp Tue Dec 10 21:35:27 2013
@@ -136,3 +136,25 @@ namespace PR7434 {
     };
   }
 }
+
+namespace LocalExternVar {
+  class test {
+  private:
+    struct private_struct { // expected-note 2{{here}}
+      int x;
+    };
+    int use_private();
+  };
+
+  int test::use_private() {
+    extern int array[sizeof(test::private_struct)]; // ok
+    return array[0];
+  }
+
+  int f() {
+    extern int array[sizeof(test::private_struct)]; // expected-error {{private}}
+    return array[0];
+  }
+
+  int array[sizeof(test::private_struct)]; // expected-error {{private}}
+}





More information about the cfe-commits mailing list