From: Douglas Gregor Date: Wed, 7 Jan 2009 02:48:43 +0000 (+0000) Subject: When determining whether a variable is a file-scoped variable, check X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17a9b9e3ee75f5dbb4819cc8ebf40eec8015f84a;p=clang When determining whether a variable is a file-scoped variable, check out its lookup context (to see through linkage specifications). Addresses . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61848 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index f5f57b46d0..5b96153d59 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -428,8 +428,8 @@ public: bool isFileVarDecl() const { if (getKind() != Decl::Var) return false; - if (isa(getDeclContext()) || - isa(getDeclContext()) ) + const DeclContext *Ctx = getDeclContext()->getLookupContext(); + if (isa(Ctx) || isa(Ctx) ) return true; return false; } diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 255067baec..e9b309bd07 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -429,7 +429,11 @@ public: /// context of this context, which corresponds to the innermost /// location from which name lookup can find the entities in this /// context. - DeclContext *getLookupContext(); + DeclContext *getLookupContext() { + return const_cast( + const_cast(this)->getLookupContext()); + } + const DeclContext *getLookupContext() const; /// getNextContext - If this is a DeclContext that may have other /// DeclContexts that are semantically connected but syntactically diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index cf612c2f3c..f14dc3c717 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -567,8 +567,8 @@ DeclContext::lookup(ASTContext &Context, DeclarationName Name) const { return const_cast(this)->lookup(Context, Name); } -DeclContext *DeclContext::getLookupContext() { - DeclContext *Ctx = this; +const DeclContext *DeclContext::getLookupContext() const { + const DeclContext *Ctx = this; while (Ctx->isTransparentContext()) Ctx = Ctx->getParent(); return Ctx; diff --git a/test/SemaCXX/linkage-spec.cpp b/test/SemaCXX/linkage-spec.cpp index 80d95fb222..6f25da0cd6 100644 --- a/test/SemaCXX/linkage-spec.cpp +++ b/test/SemaCXX/linkage-spec.cpp @@ -15,3 +15,9 @@ void test(int x, double d) { int& i1 = g(x); double& d1 = g(d); } + +extern "C" int foo; +extern "C" int foo; + +extern "C" const int bar; +extern "C" int const bar;