From: Alexander Kornienko Date: Mon, 9 Nov 2015 16:45:17 +0000 (+0000) Subject: Adjust printQualifiedName to handle unscoped enums in a way similar to anonymous... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1470b7d9fbb93aca928cf7ec55a3b0e9778d04b5;p=clang Adjust printQualifiedName to handle unscoped enums in a way similar to anonymous namespaces. Patch by Sterling Augustine! Differential revision: http://reviews.llvm.org/D14459 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252488 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 7485b12614..85724878fd 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1430,6 +1430,15 @@ void NamedDecl::printQualifiedName(raw_ostream &OS, } } OS << ')'; + } else if (const EnumDecl *ED = dyn_cast(*I)) { + // C++ [dcl.enum]p10: Each enum-name and each unscoped + // enumerator is declared in the scope that immediately contains + // the enum-specifier. Each scoped enumerator is declared in the + // scope of the enumeration. + if (ED->isScoped() || ED->getIdentifier()) + OS << *ED; + else + continue; } else { OS << *cast(*I); } diff --git a/unittests/AST/NamedDeclPrinterTest.cpp b/unittests/AST/NamedDeclPrinterTest.cpp index cf97a0abf6..92df4577ac 100644 --- a/unittests/AST/NamedDeclPrinterTest.cpp +++ b/unittests/AST/NamedDeclPrinterTest.cpp @@ -131,3 +131,45 @@ TEST(NamedDeclPrinter, TestNamespace2) { "A", "A")); } + +TEST(NamedDeclPrinter, TestUnscopedUnnamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "enum { A };", + "A", + "A")); +} + +TEST(NamedDeclPrinter, TestNamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "enum X { A };", + "A", + "X::A")); +} + +TEST(NamedDeclPrinter, TestScopedNamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "enum class X { A };", + "A", + "X::A")); +} + +TEST(NamedDeclPrinter, TestClassWithUnscopedUnnamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "class X { enum { A }; };", + "A", + "X::A")); +} + +TEST(NamedDeclPrinter, TestClassWithUnscopedNamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "class X { enum Y { A }; };", + "A", + "X::Y::A")); +} + +TEST(NamedDeclPrinter, TestClassWithScopedNamedEnum) { + ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches( + "class X { enum class Y { A }; };", + "A", + "X::Y::A")); +}