]> granicus.if.org Git - clang/commitdiff
When determining whether a variable is a file-scoped variable, check
authorDouglas Gregor <dgregor@apple.com>
Wed, 7 Jan 2009 02:48:43 +0000 (02:48 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 7 Jan 2009 02:48:43 +0000 (02:48 +0000)
out its lookup context (to see through linkage
specifications). Addresses <rdar://problem/6477142>.

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

include/clang/AST/Decl.h
include/clang/AST/DeclBase.h
lib/AST/DeclBase.cpp
test/SemaCXX/linkage-spec.cpp

index f5f57b46d005f0113e7fbbbe079ea1d304d8a33a..5b96153d595e52bdceb83f36422bc85937b34ec9 100644 (file)
@@ -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;
   }
index 255067baec0b7aa8b0593b712c6aff02fdf66607..e9b309bd072e2cd49eaac42eb5dee0e94d68ab00 100644 (file)
@@ -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
index cf612c2f3c74200ee7a71f78307655c2235602ef..f14dc3c717501414de882114ea1e88242339c93d 100644 (file)
@@ -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;
index 80d95fb222ba71e3324c65fa4043cbc804d5ef92..6f25da0cd6abe1f17b17aa8361c46b17b408e708 100644 (file)
@@ -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;