[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / PCH / cxx11-constexpr.cpp
blobb315b477dbf1c67dc7337927121e98ef9ac39444
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
4 // RUN: %clang_cc1 -pedantic-errors -std=c++11 -emit-pch -fpch-instantiate-templates %s -o %t
5 // RUN: %clang_cc1 -pedantic-errors -std=c++11 -include-pch %t -verify %s
7 #ifndef HEADER_INCLUDED
9 #define HEADER_INCLUDED
11 struct B {
12 B();
13 constexpr B(char) {}
16 struct C {
17 B b;
18 double d = 0.0;
21 struct D : B {
22 constexpr D(int n) : B('x'), k(2*n+1) {}
23 int k;
26 constexpr int value = 7;
28 template<typename T>
29 constexpr T plus_seven(T other) {
30 return value + other;
33 #else
35 static_assert(D(4).k == 9, "");
36 constexpr int f(C c) { return 0; } // expected-error {{not a literal type}}
37 // expected-note@16 {{not an aggregate and has no constexpr constructors}}
38 constexpr B b; // expected-error {{constant expression}} expected-note {{non-constexpr}}
39 // expected-note@12 {{here}}
41 static_assert(plus_seven(3) == 10, "");
43 #endif