aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-07 02:48:43 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-07 02:48:43 +0000
commit8d973111a832891e2fac54d793f68cc1b328cd8a (patch)
tree4d41fbf97feba6adc0c9faf46f59d9ac513f4c84
parentf6768bd9cb07f56690f34cf973637cda4d3197f4 (diff)
downloadllvm-8d973111a832891e2fac54d793f68cc1b328cd8a.zip
llvm-8d973111a832891e2fac54d793f68cc1b328cd8a.tar.gz
llvm-8d973111a832891e2fac54d793f68cc1b328cd8a.tar.bz2
When determining whether a variable is a file-scoped variable, check
out its lookup context (to see through linkage specifications). Addresses <rdar://problem/6477142>. llvm-svn: 61848
-rw-r--r--clang/include/clang/AST/Decl.h4
-rw-r--r--clang/include/clang/AST/DeclBase.h6
-rw-r--r--clang/lib/AST/DeclBase.cpp4
-rw-r--r--clang/test/SemaCXX/linkage-spec.cpp6
4 files changed, 15 insertions, 5 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f5f57b4..5b96153 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -428,8 +428,8 @@ public:
bool isFileVarDecl() const {
if (getKind() != Decl::Var)
return false;
- if (isa<TranslationUnitDecl>(getDeclContext()) ||
- isa<NamespaceDecl>(getDeclContext()) )
+ const DeclContext *Ctx = getDeclContext()->getLookupContext();
+ if (isa<TranslationUnitDecl>(Ctx) || isa<NamespaceDecl>(Ctx) )
return true;
return false;
}
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 255067b..e9b309b 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/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<DeclContext *>(
+ const_cast<const DeclContext *>(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/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index cf612c2..f14dc3c 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -567,8 +567,8 @@ DeclContext::lookup(ASTContext &Context, DeclarationName Name) const {
return const_cast<DeclContext*>(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/clang/test/SemaCXX/linkage-spec.cpp b/clang/test/SemaCXX/linkage-spec.cpp
index 80d95fb..6f25da0 100644
--- a/clang/test/SemaCXX/linkage-spec.cpp
+++ b/clang/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;