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
// 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());
}
};
}
}
+
+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}}
+}