diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-09-18 01:35:26 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-09-18 01:35:26 +0000 |
| commit | 785067eca75fb271e9ea3af61ba029dd3a22dd36 (patch) | |
| tree | a9b6d6f051c8180e11d7373fd012de173594c5a3 /clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp | |
| parent | e693e8432ec84152ce08d89d20e28309bb63f294 (diff) | |
| download | bcm5719-llvm-785067eca75fb271e9ea3af61ba029dd3a22dd36.tar.gz bcm5719-llvm-785067eca75fb271e9ea3af61ba029dd3a22dd36.zip | |
If a variable template specialization with an incomplete array type is
referenced, try to instantiate its definition in order to complete the type.
llvm-svn: 190910
Diffstat (limited to 'clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp')
| -rw-r--r-- | clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp index 1505481912f..c878c13906d 100644 --- a/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp +++ b/clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp @@ -4,6 +4,10 @@ #define CONST const +#ifdef PRECXX11 +#define static_assert(expr, msg) typedef int static_assert[(expr) ? 1 : -1]; +#endif + class A { template<typename T> CONST T wrong; // expected-error {{member 'wrong' declared as a template}} template<typename T> CONST T wrong_init = 5; // expected-error {{member 'wrong_init' declared as a template}} @@ -179,9 +183,7 @@ namespace in_class_template { template<typename U> static CONST U Data = U(100); }; template CONST int D3<float>::Data<int>; -#ifndef PRECXX11 static_assert(D3<float>::Data<int> == 100, ""); -#endif namespace bug_files { // FIXME: A bug has been filed addressing an issue similar to these. @@ -210,7 +212,7 @@ namespace in_class_template { } namespace other_bugs { - // FIXME: This fails to properly initilize the variable 'k'. + // FIXME: This fails to properly initialize the variable 'k'. template<typename A> struct S { template<typename B> static int V; @@ -221,6 +223,34 @@ namespace in_class_template { template<typename A> template<typename B> int S<A>::V<B> = 123; int k = S<int>::V<void>; } + + namespace incomplete_array { + template<typename T> extern T var[]; + template<typename T> T var[] = { 1, 2, 3 }; + template<> char var<char>[] = "hello"; + template<typename T> char var<T*>[] = "pointer"; + + static_assert(sizeof(var<int>) == 12, ""); + static_assert(sizeof(var<char>) == 6, ""); + static_assert(sizeof(var<void*>) == 8, ""); + + template<typename...> struct tuple; + + template<typename T> struct A { + template<typename U> static T x[]; + template<typename U> static T y[]; + + template<typename...U> static T y<tuple<U...> >[]; + }; + + // FIXME: These cases should be accepted. + int *use_before_definition = A<int>::x<char>; + template<typename T> template<typename U> T A<T>::x<U>[sizeof(U)]; // expected-error {{forward declaration}} + static_assert(sizeof(A<int>::x<char>) == 1, ""); // expected-error {{incomplete}} + + template<typename T> template<typename...U> T A<T>::y<tuple<U...> >[] = { U()... }; + static_assert(sizeof(A<int>::y<tuple<char, char, char> >) == 12, ""); // expected-error {{incomplete}} + } } namespace in_nested_classes { |

