diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/SemaTemplate/instantiate-self.cpp | 103 | ||||
-rw-r--r-- | clang/test/SemaTemplate/instantiation-depth-exception-spec.cpp | 15 | ||||
-rw-r--r-- | clang/test/SemaTemplate/instantiation-depth.cpp | 9 |
3 files changed, 105 insertions, 22 deletions
diff --git a/clang/test/SemaTemplate/instantiate-self.cpp b/clang/test/SemaTemplate/instantiate-self.cpp index cfe902509f7..916a01e63f1 100644 --- a/clang/test/SemaTemplate/instantiate-self.cpp +++ b/clang/test/SemaTemplate/instantiate-self.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -std=c++11 -verify %s +// RUN: %clang_cc1 -std=c++1z -verify -pedantic-errors %s // Check that we deal with cases where the instantiation of a class template // recursively requires the instantiation of the same template. @@ -47,9 +47,8 @@ namespace test4 { A<int> a; // expected-note {{in instantiation of}} } -// FIXME: PR12298: Recursive constexpr function template instantiation leads to +// PR12298: Recursive constexpr function template instantiation leads to // stack overflow. -#if 0 namespace test5 { template<typename T> struct A { constexpr T f(T k) { return g(k); } @@ -57,22 +56,20 @@ namespace test5 { return k ? f(k-1)+1 : 0; } }; - // This should be accepted. - constexpr int x = A<int>().f(5); + constexpr int x = A<int>().f(5); // ok } namespace test6 { template<typename T> constexpr T f(T); template<typename T> constexpr T g(T t) { - typedef int arr[f(T())]; + typedef int arr[f(T())]; // expected-error {{variable length array}} return t; } template<typename T> constexpr T f(T t) { - typedef int arr[g(T())]; + typedef int arr[g(T())]; // expected-error {{zero size array}} expected-note {{instantiation of}} return t; } - // This should be ill-formed. - int n = f(0); + int n = f(0); // expected-note 2{{instantiation of}} } namespace test7 { @@ -80,10 +77,94 @@ namespace test7 { return t; } template<typename T> constexpr T f(T t) { - typedef int arr[g(T())]; + typedef int arr[g(T() + 1)]; return t; } - // This should be accepted. int n = f(0); } + +namespace test8 { + template<typename T> struct A { + int n = A{}.n; // expected-error {{default member initializer for 'n' uses itself}} expected-note {{instantiation of default member init}} + }; + A<int> ai = {}; // expected-note {{instantiation of default member init}} +} + +namespace test9 { + template<typename T> struct A { enum class B; }; + // FIXME: It'd be nice to give the "it has not yet been instantiated" diagnostic here. + template<typename T> enum class A<T>::B { k = A<T>::B::k2, k2 = k }; // expected-error {{no member named 'k2'}} + auto k = A<int>::B::k; // expected-note {{in instantiation of}} +} + +namespace test10 { + template<typename T> struct A { + void f() noexcept(noexcept(f())); // expected-error {{exception specification of 'f' uses itself}} expected-note {{instantiation of}} + }; + bool b = noexcept(A<int>().f()); // expected-note {{instantiation of}} +} + +namespace test11 { + template<typename T> const int var = var<T>; + int k = var<int>; + + template<typename T> struct X { + static const int k = X<T>::k; + }; + template<typename T> const int X<T>::k; + int q = X<int>::k; + + template<typename T> struct Y { + static const int k; + }; + template<typename T> const int Y<T>::k = Y<T>::k; + int r = Y<int>::k; +} + +namespace test12 { + template<typename T> int f(T t, int = f(T())) {} // expected-error {{recursive evaluation of default argument}} expected-note {{instantiation of}} + struct X {}; + int q = f(X()); // expected-note {{instantiation of}} +} + +namespace test13 { + struct A { + // Cycle via type of non-type template parameter. + template<typename T, typename T::template W<T>::type U = 0> struct W { using type = int; }; + // Cycle via default template argument. + template<typename T, typename U = typename T::template X<T>> struct X {}; + template<typename T, int U = T::template Y<T>::value> struct Y { static const int value = 0; }; + template<typename T, template<typename> typename U = T::template Z<T>::template nested> struct Z { template<typename> struct nested; }; + }; + template<typename T> struct Wrap { + template<typename U> struct W : A::W<T> {}; + template<typename U> struct X : A::X<T> {}; + template<typename U> struct Y : A::Y<T> {}; + template<typename U> struct Z : A::Z<T> {}; + }; + struct B { + template<typename U> struct W { using type = int; }; + template<typename U> struct X {}; + template<typename U> struct Y { static const int value = 0; }; + template<typename U> struct Z { template<typename> struct nested; }; + }; + + A::W<B> awb; + A::X<B> axb; + A::Y<B> ayb; + A::Z<B> azb; + + A::W<Wrap<Wrap<B>>> awwwb; + A::X<Wrap<Wrap<B>>> axwwb; + A::Y<Wrap<Wrap<B>>> aywwb; + A::Z<Wrap<Wrap<B>>> azwwb; + + // FIXME: These tests cause us to use too much stack and crash on a self-hosted debug build. + // FIXME: Check for recursion here and give a better diagnostic. +#if 0 + A::W<A> awa; + A::X<A> axa; + A::Y<A> aya; + A::Z<A> aza; #endif +} diff --git a/clang/test/SemaTemplate/instantiation-depth-exception-spec.cpp b/clang/test/SemaTemplate/instantiation-depth-exception-spec.cpp index 6caa4a60e6f..3f64811bd10 100644 --- a/clang/test/SemaTemplate/instantiation-depth-exception-spec.cpp +++ b/clang/test/SemaTemplate/instantiation-depth-exception-spec.cpp @@ -1,11 +1,14 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ftemplate-depth 16 -fcxx-exceptions -fexceptions %s -template<typename T> T go(T a) noexcept(noexcept(go(a))); // \ -// expected-error 16{{call to function 'go' that is neither visible}} \ -// expected-note 16{{'go' should be declared prior to the call site}} \ -// expected-error {{recursive template instantiation exceeded maximum depth of 16}} +template<int N> struct X { + static int go(int a) noexcept(noexcept(X<N+1>::go(a))); // \ +// expected-error {{recursive template instantiation exceeded maximum depth of 16}} \ +// expected-note 9{{in instantiation of exception specification}} \ +// expected-note {{skipping 7 context}} \ +// expected-note {{use -ftemplate-depth}} +}; void f() { - int k = go(0); // \ - // expected-note {{in instantiation of exception specification for 'go<int>' requested here}} + int k = X<0>::go(0); // \ + // expected-note {{in instantiation of exception specification for 'go' requested here}} } diff --git a/clang/test/SemaTemplate/instantiation-depth.cpp b/clang/test/SemaTemplate/instantiation-depth.cpp index c0b8bb2a124..17f84c170c3 100644 --- a/clang/test/SemaTemplate/instantiation-depth.cpp +++ b/clang/test/SemaTemplate/instantiation-depth.cpp @@ -19,13 +19,12 @@ void test() { // RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 5 -ftemplate-backtrace-limit 4 -std=c++11 -DNOEXCEPT %s template<typename T> struct S { - S() noexcept(noexcept(T())); -}; -struct T : S<T> {}; \ + S() noexcept(noexcept(S<S>())); \ // expected-error{{recursive template instantiation exceeded maximum depth of 5}} \ -// expected-note 4 {{in instantiation of exception spec}} \ +// expected-note 3 {{in instantiation of exception spec}} \ // expected-note {{skipping 2 contexts in backtrace}} \ // expected-note {{use -ftemplate-depth=N to increase recursive template instantiation depth}} -T t; // expected-note {{implicit default constructor for 'T' first required here}} +}; +S<void> t; // expected-note {{in instantiation of exception spec}} #endif |