summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2015-11-09 16:45:17 +0000
committerAlexander Kornienko <alexfh@google.com>2015-11-09 16:45:17 +0000
commit4f35532dbe645f4a349ea63951d659334359abd9 (patch)
tree0d902c5247183a6f51bfe21aa6514f8cc10cc29e
parent3f5dfc256204b4f4825fbfbfc7c9f985f4e78422 (diff)
downloadbcm5719-llvm-4f35532dbe645f4a349ea63951d659334359abd9.tar.gz
bcm5719-llvm-4f35532dbe645f4a349ea63951d659334359abd9.zip
Adjust printQualifiedName to handle unscoped enums in a way similar to anonymous namespaces.
Patch by Sterling Augustine! Differential revision: http://reviews.llvm.org/D14459 llvm-svn: 252488
-rw-r--r--clang/lib/AST/Decl.cpp9
-rw-r--r--clang/unittests/AST/NamedDeclPrinterTest.cpp42
2 files changed, 51 insertions, 0 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 7485b12614d..85724878fd4 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -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);
}
diff --git a/clang/unittests/AST/NamedDeclPrinterTest.cpp b/clang/unittests/AST/NamedDeclPrinterTest.cpp
index cf97a0abf6c..92df4577ac7 100644
--- a/clang/unittests/AST/NamedDeclPrinterTest.cpp
+++ b/clang/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"));
+}
OpenPOWER on IntegriCloud