instantiation-depth-defarg.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // RUN: %clang_cc1 -fsyntax-only -verify -ftemplate-depth 128 -ftemplate-backtrace-limit 4 %s
  2. template<int N> struct S {
  3. typedef typename S<N-1>::type type;
  4. static int f(int n = S<N-1>::f()); // \
  5. // expected-error{{recursive template instantiation exceeded maximum depth of 128}} \
  6. // expected-note 3 {{instantiation of default function argument}} \
  7. // expected-note {{skipping 125 contexts in backtrace}} \
  8. // expected-note {{use -ftemplate-depth=N to increase recursive template instantiation depth}}
  9. };
  10. template<> struct S<0> {
  11. typedef int type;
  12. };
  13. // Incrementally instantiate up to S<2048>.
  14. template struct S<128>;
  15. template struct S<256>;
  16. template struct S<384>;
  17. template struct S<512>;
  18. template struct S<640>;
  19. template struct S<768>;
  20. template struct S<896>;
  21. template struct S<1024>;
  22. template struct S<1152>;
  23. template struct S<1280>;
  24. template struct S<1408>;
  25. template struct S<1536>;
  26. template struct S<1664>;
  27. template struct S<1792>;
  28. template struct S<1920>;
  29. template struct S<2048>;
  30. // Check that we actually bail out when we hit the instantiation depth limit for
  31. // the default arguments.
  32. void g() { S<2048>::f(); } // expected-note {{required here}}