]> granicus.if.org Git - clang/commitdiff
[AST] namespace ns { extern "C" { int X; }} prints as "ns::X", not as "X"
authorSam McCall <sam.mccall@gmail.com>
Fri, 2 Feb 2018 13:34:47 +0000 (13:34 +0000)
committerSam McCall <sam.mccall@gmail.com>
Fri, 2 Feb 2018 13:34:47 +0000 (13:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324081 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Decl.cpp
unittests/AST/NamedDeclPrinterTest.cpp

index 9c73ee7ede3b7505da71590c46cb95c0a94303a4..30599ea7cfbe025f8b54c9f1b53422c2c8f9f87d 100644 (file)
@@ -1497,9 +1497,10 @@ void NamedDecl::printQualifiedName(raw_ostream &OS,
   using ContextsTy = SmallVector<const DeclContext *, 8>;
   ContextsTy Contexts;
 
-  // Collect contexts.
-  while (Ctx && isa<NamedDecl>(Ctx)) {
-    Contexts.push_back(Ctx);
+  // Collect named contexts.
+  while (Ctx) {
+    if (isa<NamedDecl>(Ctx))
+      Contexts.push_back(Ctx);
     Ctx = Ctx->getParent();
   }
 
index 002bb28f374d464ac55638130adde76926ccfba3..5715a341d81339f16d630ea3921ebadbe8a40bb9 100644 (file)
@@ -173,3 +173,10 @@ TEST(NamedDeclPrinter, TestClassWithScopedNamedEnum) {
     "A",
     "X::Y::A"));
 }
+
+TEST(NamedDeclPrinter, TestLinkageInNamespace) {
+  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
+    "namespace X { extern \"C\" { int A; } }",
+    "A",
+    "X::A"));
+}