instantiate-var-template.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // RUN: %clang_cc1 -verify -std=c++1y %s
  2. namespace PR17846 {
  3. template <typename T> constexpr T pi = T(3.14);
  4. template <typename T> constexpr T tau = 2 * pi<T>;
  5. constexpr double tau_double = tau<double>;
  6. static_assert(tau_double == 6.28, "");
  7. }
  8. namespace PR17848 {
  9. template<typename T> constexpr T var = 12345;
  10. template<typename T> constexpr T f() { return var<T>; }
  11. constexpr int k = f<int>();
  12. static_assert(k == 12345, "");
  13. }
  14. namespace NonDependent {
  15. template<typename T> constexpr T a = 0;
  16. template<typename T> constexpr T b = a<int>;
  17. static_assert(b<int> == 0, "");
  18. }
  19. namespace InstantiationDependent {
  20. int f(int);
  21. void f(char);
  22. template<int> constexpr int a = 1;
  23. template<typename T> constexpr T b = a<sizeof(sizeof(f(T())))>; // expected-error {{invalid application of 'sizeof' to an incomplete type 'void'}}
  24. static_assert(b<int> == 1, "");
  25. static_assert(b<char> == 1, ""); // expected-note {{in instantiation of}} expected-error {{not an integral constant}}
  26. template<typename T> void f() {
  27. static_assert(a<sizeof(sizeof(f(T())))> == 0, ""); // expected-error {{static_assert failed}}
  28. }
  29. }