fork download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. static A const DEFAULT;
  6.  
  7. constexpr A(int value = {}) : _value{ value } {}
  8.  
  9. constexpr operator int() const { return _value; }
  10.  
  11. int const _value;
  12. };
  13.  
  14. constexpr A const A::DEFAULT{};
  15.  
  16. template<typename = void>
  17. struct B_impl
  18. {
  19. static B_impl const DEFAULT;
  20.  
  21. constexpr B_impl(int value = {}) : _value{ value } {}
  22.  
  23. constexpr operator int() const { return _value; }
  24.  
  25. int const _value;
  26. };
  27.  
  28. template<typename T>
  29. constexpr B_impl<T> const B_impl<T>::DEFAULT{};
  30.  
  31. using B = B_impl<>;
  32.  
  33. template<int N>
  34. constexpr int foo() { return N; }
  35.  
  36. int main(int, char**) noexcept
  37. {
  38. std::cout << "A: " << foo<A::DEFAULT>() << "\n"; // IntelliSense hates this
  39. std::cout << "B: " << foo<B::DEFAULT>() << "\n"; // VC++ and clang die here:
  40. // MSVC error: C2975 'N': invalid template argument for 'foo', expected compile-time constant expression
  41. // clang error: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'N'
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 4252KB
stdin
Standard input is empty
stdout
A: 0
B: 0