[cfe-commits] r61848 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp test/SemaCXX/linkage-spec.cpp
Douglas Gregor
dgregor at apple.com
Tue Jan 6 18:48:44 PST 2009
Author: dgregor
Date: Tue Jan 6 20:48:43 2009
New Revision: 61848
URL: http://llvm.org/viewvc/llvm-project?rev=61848&view=rev
Log:
When determining whether a variable is a file-scoped variable, check
out its lookup context (to see through linkage
specifications). Addresses <rdar://problem/6477142>.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/test/SemaCXX/linkage-spec.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=61848&r1=61847&r2=61848&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Jan 6 20:48:43 2009
@@ -428,8 +428,8 @@
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;
}
Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=61848&r1=61847&r2=61848&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Tue Jan 6 20:48:43 2009
@@ -429,7 +429,11 @@
/// 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
Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=61848&r1=61847&r2=61848&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Jan 6 20:48:43 2009
@@ -567,8 +567,8 @@
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;
Modified: cfe/trunk/test/SemaCXX/linkage-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/linkage-spec.cpp?rev=61848&r1=61847&r2=61848&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/linkage-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/linkage-spec.cpp Tue Jan 6 20:48:43 2009
@@ -15,3 +15,9 @@
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;
More information about the cfe-commits
mailing list