Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 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 | |
| 4 | #ifndef HEADER_INCLUDED |
| 5 | |
| 6 | #define HEADER_INCLUDED |
| 7 | |
| 8 | struct B { |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 9 | B(); |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 10 | constexpr B(char) {} |
| 11 | }; |
| 12 | |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 13 | struct C { |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 14 | B b; |
| 15 | double d = 0.0; |
| 16 | }; |
| 17 | |
| 18 | struct D : B { |
| 19 | constexpr D(int n) : B('x'), k(2*n+1) {} |
| 20 | int k; |
| 21 | }; |
| 22 | |
Douglas Gregor | 67d45ec | 2012-09-20 23:43:29 +0000 | [diff] [blame] | 23 | constexpr int value = 7; |
| 24 | |
| 25 | template<typename T> |
| 26 | constexpr T plus_seven(T other) { |
| 27 | return value + other; |
| 28 | } |
| 29 | |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 30 | #else |
| 31 | |
| 32 | static_assert(D(4).k == 9, ""); |
| 33 | constexpr int f(C c) { return 0; } // expected-error {{not a literal type}} |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 34 | // expected-note@13 {{not an aggregate and has no constexpr constructors}} |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 35 | constexpr B b; // expected-error {{constant expression}} expected-note {{non-constexpr}} |
Jordan Rose | 78541c4 | 2012-07-11 19:58:23 +0000 | [diff] [blame] | 36 | // expected-note@9 {{here}} |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 37 | |
Douglas Gregor | 67d45ec | 2012-09-20 23:43:29 +0000 | [diff] [blame] | 38 | static_assert(plus_seven(3) == 10, ""); |
| 39 | |
Richard Smith | dfefb84 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 40 | #endif |