// 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. namespace test1 { template struct A { struct B { // expected-note {{not complete until the closing '}'}} B b; // expected-error {{has incomplete type 'test1::A::B'}} }; B b; // expected-note {{in instantiation of}} }; A a; // expected-note {{in instantiation of}} } namespace test2 { template struct A { struct B { struct C {}; char c[1 + C()]; // expected-error {{invalid operands to binary expression}} friend constexpr int operator+(int, C) { return 4; } }; B b; // expected-note {{in instantiation of}} }; A a; // expected-note {{in instantiation of}} } namespace test3 { // PR12317 template struct A { struct B { enum { Val = 1 }; char c[1 + Val]; // ok }; B b; }; A a; } namespace test4 { template struct M { typedef int type; }; template struct A { struct B { // expected-note {{not complete until the closing '}'}} int k[typename A::type>::B().k[0] + 1]; // expected-error {{incomplete type}} }; B b; // expected-note {{in instantiation of}} }; A a; // expected-note {{in instantiation of}} } // PR12298: Recursive constexpr function template instantiation leads to // stack overflow. namespace test5 { template struct A { constexpr T f(T k) { return g(k); } constexpr T g(T k) { return k ? f(k-1)+1 : 0; } }; constexpr int x = A().f(5); // ok } namespace test6 { template constexpr T f(T); template constexpr T g(T t) { // FIXME: It'd be nice to say that the function is currently being defined, rather than being undefined. typedef int arr[f(T())]; // expected-error {{variable length array}} expected-note {{undefined function 'f'}} return t; } template constexpr T f(T t) { // expected-note {{declared here}} typedef int arr[g(T())]; // expected-error {{zero size array}} expected-note {{instantiation of}} return t; } int n = f(0); // expected-note 2{{instantiation of}} } namespace test7 { template constexpr T g(T t) { return t; } template constexpr T f(T t) { typedef int arr[g(T() + 1)]; return t; } int n = f(0); } namespace test8 { template struct A { int n = A{}.n; // expected-error {{default member initializer for 'n' uses itself}} expected-note {{instantiation of default member init}} }; A ai = {}; // expected-note {{instantiation of default member init}} } namespace test9 { template struct A { enum class B; }; // FIXME: It'd be nice to give the "it has not yet been instantiated" diagnostic here. template enum class A::B { k = A::B::k2, k2 = k }; // expected-error {{no member named 'k2'}} auto k = A::B::k; // expected-note {{in instantiation of}} } namespace test10 { template struct A { void f() noexcept(noexcept(f())); // expected-error {{exception specification of 'f' uses itself}} expected-note {{instantiation of}} }; bool b = noexcept(A().f()); // expected-note {{instantiation of}} } namespace test11 { template const int var = var; int k = var; template struct X { static const int b = false; static const int k = X::b ? X::k : 0; }; template const int X::k; int q = X::k; template struct Y { static const int k; }; // OK (but not constant initialization). template const int Y::k = Y::k; int r = Y::k; } namespace test12 { template 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::type U = 0> struct W { using type = int; }; // Cycle via default template argument. template> struct X {}; template::value> struct Y { static const int value = 0; }; template typename U = T::template Z::template nested> struct Z { template struct nested; }; }; template struct Wrap { template struct W : A::W {}; template struct X : A::X {}; template struct Y : A::Y {}; template struct Z : A::Z {}; }; struct B { template struct W { using type = int; }; template struct X {}; template struct Y { static const int value = 0; }; template struct Z { template struct nested; }; }; A::W awb; A::X axb; A::Y ayb; A::Z azb; A::W>> awwwb; A::X>> axwwb; A::Y>> aywwb; A::Z>> 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 awa; A::X axa; A::Y aya; A::Z aza; #endif }