r321312 - [AST] Incorrectly qualified unscoped enumeration as template actual parameter.
Paul Robinson via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 21 13:47:22 PST 2017
Author: probinson
Date: Thu Dec 21 13:47:22 2017
New Revision: 321312
URL: http://llvm.org/viewvc/llvm-project?rev=321312&view=rev
Log:
[AST] Incorrectly qualified unscoped enumeration as template actual parameter.
An unscoped enumeration used as template argument, should not have any
qualified information about its enclosing scope, as its visibility is
global.
In the case of scoped enumerations, they must include information
about their enclosing scope.
Patch by Carlos Alberto Enciso!
Differential Revision: https://reviews.llvm.org/D39239
Added:
cfe/trunk/test/SemaTemplate/temp_arg_enum_printing_more.cpp
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/Modules/odr.cpp
cfe/trunk/test/SemaCXX/return-noreturn.cpp
cfe/trunk/test/SemaTemplate/temp_arg_enum_printing.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=321312&r1=321311&r2=321312&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Dec 21 13:47:22 2017
@@ -1548,7 +1548,10 @@ void NamedDecl::printQualifiedName(raw_o
// 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())
+ // For the case of unscoped enumerator, do not include in the qualified
+ // name any information about its enum enclosing scope, as is visibility
+ // is global.
+ if (ED->isScoped())
OS << *ED;
else
continue;
Modified: cfe/trunk/test/Modules/odr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr.cpp?rev=321312&r1=321311&r2=321312&view=diff
==============================================================================
--- cfe/trunk/test/Modules/odr.cpp (original)
+++ cfe/trunk/test/Modules/odr.cpp Thu Dec 21 13:47:22 2017
@@ -18,6 +18,6 @@ int x = f() + g();
// expected-note at a.h:3 {{declaration of 'f' does not match}}
// expected-note at a.h:1 {{definition has no member 'm'}}
-// expected-error at b.h:5 {{'E::e2' from module 'b' is not present in definition of 'E' in module 'a'}}
+// expected-error at b.h:5 {{'e2' from module 'b' is not present in definition of 'E' in module 'a'}}
// expected-error at b.h:3 {{'Y::f' from module 'b' is not present in definition of 'Y' in module 'a'}}
// expected-error at b.h:2 {{'Y::m' from module 'b' is not present in definition of 'Y' in module 'a'}}
Modified: cfe/trunk/test/SemaCXX/return-noreturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/return-noreturn.cpp?rev=321312&r1=321311&r2=321312&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/return-noreturn.cpp (original)
+++ cfe/trunk/test/SemaCXX/return-noreturn.cpp Thu Dec 21 13:47:22 2017
@@ -143,7 +143,7 @@ template <PR9412_MatchType type> int PR9
} // expected-warning {{control reaches end of non-void function}}
void PR9412_f() {
- PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<PR9412_MatchType::PR9412_Exact>' requested here}}
+ PR9412_t<PR9412_Exact>(); // expected-note {{in instantiation of function template specialization 'PR9412_t<PR9412_Exact>' requested here}}
}
struct NoReturn {
Modified: cfe/trunk/test/SemaTemplate/temp_arg_enum_printing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_enum_printing.cpp?rev=321312&r1=321311&r2=321312&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_arg_enum_printing.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_enum_printing.cpp Thu Dec 21 13:47:22 2017
@@ -13,9 +13,9 @@ template <NamedEnum E>
void foo();
void test() {
- // CHECK: template<> void foo<NamedEnumNS::NamedEnum::Val0>()
+ // CHECK: template<> void foo<NamedEnumNS::Val0>()
NamedEnumNS::foo<Val0>();
- // CHECK: template<> void foo<NamedEnumNS::NamedEnum::Val1>()
+ // CHECK: template<> void foo<NamedEnumNS::Val1>()
NamedEnumNS::foo<(NamedEnum)1>();
// CHECK: template<> void foo<2>()
NamedEnumNS::foo<(NamedEnum)2>();
Added: cfe/trunk/test/SemaTemplate/temp_arg_enum_printing_more.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_enum_printing_more.cpp?rev=321312&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_arg_enum_printing_more.cpp (added)
+++ cfe/trunk/test/SemaTemplate/temp_arg_enum_printing_more.cpp Thu Dec 21 13:47:22 2017
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -ast-print %s -std=c++11 | FileCheck %s
+
+// Make sure that for template value arguments that are unscoped enumerators,
+// no qualified enum information is included in their name, as their visibility
+// is global. In the case of scoped enumerators, they must include information
+// about their enum enclosing scope.
+
+enum E1 { e1 };
+template<E1 v> struct tmpl_1 {};
+// CHECK: template<> struct tmpl_1<e1>
+tmpl_1<E1::e1> TMPL_1; // Name must be 'e1'.
+
+namespace nsp_1 { enum E2 { e2 }; }
+template<nsp_1::E2 v> struct tmpl_2 {};
+// CHECK: template<> struct tmpl_2<nsp_1::e2>
+tmpl_2<nsp_1::E2::e2> TMPL_2; // Name must be 'nsp_1::e2'.
+
+enum class E3 { e3 };
+template<E3 v> struct tmpl_3 {};
+// CHECK: template<> struct tmpl_3<E3::e3>
+tmpl_3<E3::e3> TMPL_3; // Name must be 'E3::e3'.
+
+namespace nsp_2 { enum class E4 { e4 }; }
+template<nsp_2::E4 v> struct tmpl_4 {};
+// CHECK: template<> struct tmpl_4<nsp_2::E4::e4>
+tmpl_4<nsp_2::E4::e4> TMPL_4; // Name must be 'nsp_2::E4::e4'.
Modified: cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp?rev=321312&r1=321311&r2=321312&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/NamedDeclPrinterTest.cpp Thu Dec 21 13:47:22 2017
@@ -143,7 +143,7 @@ TEST(NamedDeclPrinter, TestNamedEnum) {
ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
"enum X { A };",
"A",
- "X::A"));
+ "A"));
}
TEST(NamedDeclPrinter, TestScopedNamedEnum) {
@@ -164,7 +164,7 @@ TEST(NamedDeclPrinter, TestClassWithUnsc
ASSERT_TRUE(PrintedWrittenNamedDeclCXX11Matches(
"class X { enum Y { A }; };",
"A",
- "X::Y::A"));
+ "X::A"));
}
TEST(NamedDeclPrinter, TestClassWithScopedNamedEnum) {
More information about the cfe-commits
mailing list