r252488 - Adjust printQualifiedName to handle unscoped enums in a way similar to anonymous namespaces.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 08:45:17 PST 2015


Author: alexfh
Date: Mon Nov  9 10:45:17 2015
New Revision: 252488

URL: http://llvm.org/viewvc/llvm-project?rev=252488&view=rev
Log:
Adjust printQualifiedName to handle unscoped enums in a way similar to anonymous namespaces.

Patch by Sterling Augustine!

Differential revision: http://reviews.llvm.org/D14459

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=252488&r1=252487&r2=252488&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Nov  9 10:45:17 2015
@@ -1430,6 +1430,15 @@ void NamedDecl::printQualifiedName(raw_o
         }
       }
       OS << ')';
+    } else if (const EnumDecl *ED = dyn_cast<EnumDecl>(*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<NamedDecl>(*I);
     }

Modified: cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp?rev=252488&r1=252487&r2=252488&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp Mon Nov  9 10:45:17 2015
@@ -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"));
+}




More information about the cfe-commits mailing list