r324081 - [AST] namespace ns { extern "C" { int X; }} prints as "ns::X", not as "X"

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 05:34:48 PST 2018


Author: sammccall
Date: Fri Feb  2 05:34:47 2018
New Revision: 324081

URL: http://llvm.org/viewvc/llvm-project?rev=324081&view=rev
Log:
[AST] namespace ns { extern "C" { int X; }} prints as "ns::X", not as "X"

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=324081&r1=324080&r2=324081&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Fri Feb  2 05:34:47 2018
@@ -1497,9 +1497,10 @@ void NamedDecl::printQualifiedName(raw_o
   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();
   }
 

Modified: cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp?rev=324081&r1=324080&r2=324081&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp Fri Feb  2 05:34:47 2018
@@ -173,3 +173,10 @@ TEST(NamedDeclPrinter, TestClassWithScop
     "A",
     "X::Y::A"));
 }
+
+TEST(NamedDeclPrinter, TestLinkageInNamespace) {
+  ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
+    "namespace X { extern \"C\" { int A; } }",
+    "A",
+    "X::A"));
+}




More information about the cfe-commits mailing list