Procházet zdrojové kódy

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324081 91177308-0d34-0410-b5e6-96231b3b80d8
Sam McCall před 7 roky
rodič
revize
e705029e94
2 změnil soubory, kde provedl 11 přidání a 3 odebrání
  1. 4 3
      lib/AST/Decl.cpp
  2. 7 0
      unittests/AST/NamedDeclPrinterTest.cpp

+ 4 - 3
lib/AST/Decl.cpp

@@ -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();
   }
 

+ 7 - 0
unittests/AST/NamedDeclPrinterTest.cpp

@@ -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"));
+}