]> granicus.if.org Git - clang/commitdiff
Adjust printQualifiedName to handle unscoped enums in a way similar to anonymous...
authorAlexander Kornienko <alexfh@google.com>
Mon, 9 Nov 2015 16:45:17 +0000 (16:45 +0000)
committerAlexander Kornienko <alexfh@google.com>
Mon, 9 Nov 2015 16:45:17 +0000 (16:45 +0000)
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

lib/AST/Decl.cpp
unittests/AST/NamedDeclPrinterTest.cpp

index 7485b12614d3a192a427f88ec47acd1dca3ec282..85724878fd4792c81c8cea10057e78069edca1ed 100644 (file)
@@ -1430,6 +1430,15 @@ void NamedDecl::printQualifiedName(raw_ostream &OS,
         }
       }
       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);
     }
index cf97a0abf6c8b01f0cff09527ca48577bab9361c..92df4577ac77942bdb4fd5abfbdc496bdd9a5f0d 100644 (file)
@@ -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"));
+}