cxx11-constexpr.cpp 826 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch %s -o %t
  2. // RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s
  3. #ifndef HEADER_INCLUDED
  4. #define HEADER_INCLUDED
  5. struct B {
  6. B();
  7. constexpr B(char) {}
  8. };
  9. struct C {
  10. B b;
  11. double d = 0.0;
  12. };
  13. struct D : B {
  14. constexpr D(int n) : B('x'), k(2*n+1) {}
  15. int k;
  16. };
  17. constexpr int value = 7;
  18. template<typename T>
  19. constexpr T plus_seven(T other) {
  20. return value + other;
  21. }
  22. #else
  23. static_assert(D(4).k == 9, "");
  24. constexpr int f(C c) { return 0; } // expected-error {{not a literal type}}
  25. // expected-note@13 {{not an aggregate and has no constexpr constructors}}
  26. constexpr B b; // expected-error {{constant expression}} expected-note {{non-constexpr}}
  27. // expected-note@9 {{here}}
  28. static_assert(plus_seven(3) == 10, "");
  29. #endif