diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-14 23:13:10 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-14 23:13:10 +0000 |
commit | f1c66b40213784a1c4612f04c14cafa2b0e89988 (patch) | |
tree | e7ce75134aa9dfc30fce2b5a85088baf65423294 /test/CXX | |
parent | 59e7f4e6e69872d2fc4031f66b47b8ad64967e51 (diff) |
Instantiating a class template should not instantiate the definition of any
scoped enumeration members. Later uses of an enumeration temploid as a nested
name specifier should cause its instantiation. Plus some groundwork for
explicit specialization of member enumerations of class templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152750 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r-- | test/CXX/temp/temp.spec/temp.explicit/p8.cpp | 23 | ||||
-rw-r--r-- | test/CXX/temp/temp.spec/temp.inst/p1.cpp | 104 |
2 files changed, 122 insertions, 5 deletions
diff --git a/test/CXX/temp/temp.spec/temp.explicit/p8.cpp b/test/CXX/temp/temp.spec/temp.explicit/p8.cpp index 0c5aec3b0b..550078ab14 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p8.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p8.cpp @@ -1,16 +1,15 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s template<typename T> struct X0 { struct MemberClass; - + T* f0(T* ptr); - + static T* static_member; }; -template class X0<int>; // okay -template class X0<int(int)>; // okay; nothing gets instantiated. +template class X0<int(int)>; // ok; nothing gets instantiated. template<typename T> struct X0<T>::MemberClass { @@ -25,3 +24,17 @@ T* X0<T>::f0(T* ptr) { template<typename T> T* X0<T>::static_member = 0; +template class X0<int>; // ok + + +template<typename T> +struct X1 { + enum class E { + e = T::error // expected-error 2{{no members}} + }; +}; +template struct X1<int>; // expected-note {{here}} + +extern template struct X1<char>; // ok + +template struct X1<char>; // expected-note {{here}} diff --git a/test/CXX/temp/temp.spec/temp.inst/p1.cpp b/test/CXX/temp/temp.spec/temp.inst/p1.cpp new file mode 100644 index 0000000000..8684fc4dab --- /dev/null +++ b/test/CXX/temp/temp.spec/temp.inst/p1.cpp @@ -0,0 +1,104 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s + +// The implicit specialization of a class template specialuzation causes the +// implicit instantiation of the declarations, but not the definitions or +// default arguments, of: + +// FIXME: Many omitted cases + +// - scoped member enumerations +namespace ScopedEnum { + template<typename T> struct ScopedEnum1 { + enum class E { + e = T::error // expected-error {{'double' cannot be used prior to '::'}} + }; + }; + ScopedEnum1<int> se1; // ok + + template<typename T> struct ScopedEnum2 { + enum class E : T { // expected-error {{non-integral type 'void *' is an invalid underlying type}} + e = 0 + }; + }; + ScopedEnum2<void*> se2; // expected-note {{here}} + + template<typename T> struct UnscopedEnum3 { + enum class E : T { + e = 4 + }; + int arr[(int)E::e]; + }; + UnscopedEnum3<int> ue3; // ok + + ScopedEnum1<double>::E e1; // ok + ScopedEnum1<double>::E e2 = decltype(e2)::e; // expected-note {{in instantiation of enumeration 'ScopedEnum::ScopedEnum1<double>::E' requested here}} + + // The behavior for enums defined within function templates is not clearly + // specified by the standard. We follow the rules for enums defined within + // class templates. + template<typename T> + int f() { + enum class E { + e = T::error + }; + return (int)E(); + } + int test1 = f<int>(); + + template<typename T> + int g() { + enum class E { + e = T::error // expected-error {{has no members}} + }; + return E::e; // expected-note {{here}} + } + int test2 = g<int>(); // expected-note {{here}} +} + +// And it cases the implicit instantiations of the definitions of: + +// - unscoped member enumerations +namespace UnscopedEnum { + template<typename T> struct UnscopedEnum1 { + enum E { + e = T::error // expected-error {{'int' cannot be used prior to '::'}} + }; + }; + UnscopedEnum1<int> ue1; // expected-note {{here}} + + template<typename T> struct UnscopedEnum2 { + enum E : T { // expected-error {{non-integral type 'void *' is an invalid underlying type}} + e = 0 + }; + }; + UnscopedEnum2<void*> ue2; // expected-note {{here}} + + template<typename T> struct UnscopedEnum3 { + enum E : T { + e = 4 + }; + int arr[E::e]; + }; + UnscopedEnum3<int> ue3; // ok + + template<typename T> + int f() { + enum E { + e = T::error // expected-error {{has no members}} + }; + return (int)E(); + } + int test1 = f<int>(); // expected-note {{here}} + + template<typename T> + int g() { + enum E { + e = T::error // expected-error {{has no members}} + }; + return E::e; + } + int test2 = g<int>(); // expected-note {{here}} +} + +// FIXME: +//- - member anonymous unions |