blob: 8b722ce980951fd111e6f1f945f4ea3d4f2bc308 [file] [log] [blame]
Richard Smithdfefb842012-02-25 07:33:38 +00001// 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
4#ifndef HEADER_INCLUDED
5
6#define HEADER_INCLUDED
7
8struct B {
Jordan Rose78541c42012-07-11 19:58:23 +00009 B();
Richard Smithdfefb842012-02-25 07:33:38 +000010 constexpr B(char) {}
11};
12
Jordan Rose78541c42012-07-11 19:58:23 +000013struct C {
Richard Smithdfefb842012-02-25 07:33:38 +000014 B b;
15 double d = 0.0;
16};
17
18struct D : B {
19 constexpr D(int n) : B('x'), k(2*n+1) {}
20 int k;
21};
22
Douglas Gregor67d45ec2012-09-20 23:43:29 +000023constexpr int value = 7;
24
25template<typename T>
26constexpr T plus_seven(T other) {
27 return value + other;
28}
29
Richard Smithdfefb842012-02-25 07:33:38 +000030#else
31
32static_assert(D(4).k == 9, "");
33constexpr int f(C c) { return 0; } // expected-error {{not a literal type}}
Jordan Rose78541c42012-07-11 19:58:23 +000034// expected-note@13 {{not an aggregate and has no constexpr constructors}}
Richard Smithdfefb842012-02-25 07:33:38 +000035constexpr B b; // expected-error {{constant expression}} expected-note {{non-constexpr}}
Jordan Rose78541c42012-07-11 19:58:23 +000036 // expected-note@9 {{here}}
Richard Smithdfefb842012-02-25 07:33:38 +000037
Douglas Gregor67d45ec2012-09-20 23:43:29 +000038static_assert(plus_seven(3) == 10, "");
39
Richard Smithdfefb842012-02-25 07:33:38 +000040#endif