Skip to content

Commit

Permalink
Adjust printQualifiedName to handle unscoped enums in a way similar t…
Browse files Browse the repository at this point in the history
…o anonymous namespaces.

Patch by Sterling Augustine!

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

llvm-svn: 252488
  • Loading branch information
alexfh committed Nov 9, 2015
1 parent 3f5dfc2 commit 4f35532
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
42 changes: 42 additions & 0 deletions clang/unittests/AST/NamedDeclPrinterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

0 comments on commit 4f35532

Please sign in to comment.