summaryrefslogtreecommitdiffstats
path: root/clang/test/CXX/special/class.ctor/p6-0x.cpp
blob: 19e324d8df65b8e403a814f3f45f0d2c0ce47556 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11

// Implicitly-defined default constructors are constexpr if the implicit
// definition would be.
struct NonConstexpr1 { // expected-note {{here}}
  int a;
};
struct NonConstexpr2 { // expected-note {{here}}
  NonConstexpr1 nl;
};
constexpr NonConstexpr1 nc1 = NonConstexpr1(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor 'NonConstexpr1'}}
constexpr NonConstexpr2 nc2 = NonConstexpr2(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor 'NonConstexpr2'}}

struct Constexpr1 {};
constexpr Constexpr1 c1 = Constexpr1(); // ok
struct NonConstexpr3 : virtual Constexpr1 {};
constexpr NonConstexpr3 nc3 = NonConstexpr3(); // expected-error {{constant expression}} expected-note {{non-literal type 'const NonConstexpr3'}}

struct Constexpr2 {
  int a = 0;
};
constexpr Constexpr2 c2 = Constexpr2(); // ok

int n;
struct Member {
  Member() : a(n) {}
  constexpr Member(int&a) : a(a) {}
  int &a;
};
struct NonConstexpr4 { // expected-note {{here}}
  Member m;
};
constexpr NonConstexpr4 nc4 = NonConstexpr4(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor 'NonConstexpr4'}}
struct Constexpr3 {
  constexpr Constexpr3() : m(n) {}
  Member m;
};
constexpr Constexpr3 c3 = Constexpr3(); // ok
struct Constexpr4 {
  Constexpr3 m;
};
constexpr Constexpr4 c4 = Constexpr4(); // ok


// This rule breaks some legal C++98 programs!
struct A {}; // expected-note {{here}}
struct B {
  friend A::A(); // expected-error {{non-constexpr declaration of 'A' follows constexpr declaration}}
};
OpenPOWER on IntegriCloud