From: Sam McCall Date: Fri, 2 Feb 2018 13:34:47 +0000 (+0000) Subject: [AST] namespace ns { extern "C" { int X; }} prints as "ns::X", not as "X" X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e705029e94d188e30987bf3154b69a8a57aee3f1;p=clang [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 --- diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 9c73ee7ede..30599ea7cf 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1497,9 +1497,10 @@ void NamedDecl::printQualifiedName(raw_ostream &OS, using ContextsTy = SmallVector; ContextsTy Contexts; - // Collect contexts. - while (Ctx && isa(Ctx)) { - Contexts.push_back(Ctx); + // Collect named contexts. + while (Ctx) { + if (isa(Ctx)) + Contexts.push_back(Ctx); Ctx = Ctx->getParent(); } diff --git a/unittests/AST/NamedDeclPrinterTest.cpp b/unittests/AST/NamedDeclPrinterTest.cpp index 002bb28f37..5715a341d8 100644 --- a/unittests/AST/NamedDeclPrinterTest.cpp +++ b/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")); +}