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