]> granicus.if.org Git - clang/commitdiff
When performing a delayed access check, use the surrounding lexical context for
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 11 Dec 2013 03:35:27 +0000 (03:35 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 11 Dec 2013 03:35:27 +0000 (03:35 +0000)
any local extern declaration, not just a local extern function.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197000 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaAccess.cpp
test/SemaCXX/access.cpp

index 61dc157f858972f14e1f515e7019a09ae1abb8ab..b7df3244caab9f4c30209b60778fb13c7e336cb6 100644 (file)
@@ -1482,11 +1482,10 @@ void Sema::HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *D) {
   // 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());
   }
index 5ccd418c1b767320a17c47ab91d3b7dfc1e5f381..5fa1509c530213227095f72963b3ba54701cff08 100644 (file)
@@ -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}}
+}