1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 
6 #if __cplusplus < 201103L
7 // expected-error@+1 {{variadic macro}}
8 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
9 #endif
10 
11 namespace dr2100 { // dr2100: 12
12   template<const int *P, bool = true> struct X {};
13   template<typename T> struct A {
14     static const int n = 1;
fdr2100::A15     int f() {
16       return X<&n>::n; // ok, value-dependent
17     }
gdr2100::A18     int g() {
19       static const int n = 2;
20       return X<&n>::n; // ok, value-dependent
21 #if __cplusplus < 201702L
22       // expected-error@-2 {{does not have linkage}} expected-note@-3 {{here}}
23 #endif
24     }
25   };
26   template<const int *P> struct X<P> {
27 #if __cplusplus < 201103L
28     static const int n = 0;
29 #else
30     static const int n = *P;
31 #endif
32   };
33   int q = A<int>().f() + A<int>().g();
34 
35   // Corresponding constructs where the address is not taken are not
36   // value-dependent.
37   template<int N, bool = true> struct Y {};
38   template<typename T> struct B {
39     static const int n = 1;
fdr2100::B40     int f() {
41       return Y<n>::declared_later; // expected-error {{no member named 'declared_later'}}
42     }
gdr2100::B43     int g() {
44       static const int n = 2;
45       return Y<n>::declared_later; // expected-error {{no member named 'declared_later'}}
46     }
47   };
48   template<int N> struct Y<N> {
49     static const int declared_later = 0;
50   };
51 }
52 
53 namespace dr2103 { // dr2103: yes
f()54   void f() {
55     int a;
56     int &r = a; // expected-note {{here}}
57     struct Inner {
58       void f() {
59         int &s = r; // expected-error {{enclosing function}}
60         (void)s;
61       }
62     };
63   }
64 }
65 
66 namespace dr2120 { // dr2120: 7
67   struct A {};
68   struct B : A {};
69   struct C { A a; };
70   struct D { C c[5]; };
71   struct E : B { D d; };
72   static_assert(__is_standard_layout(B), "");
73   static_assert(__is_standard_layout(D), "");
74   static_assert(!__is_standard_layout(E), "");
75 }
76 
77 namespace dr2126 { // dr2126: 12
78 #if __cplusplus >= 201103L
79   struct A { int n; };
80 
81   const A &a = {1};              // const temporary
82   A &b = (A &)(const A &)A{1};   // const temporary
83   A &&c = (A &&)(const A &)A{1}; // const temporary
84 
85   A &&d = {1};                   // non-const temporary expected-note {{here}}
86   const A &e = (A &)(A &&) A{1}; // non-const temporary expected-note {{here}}
87   A &&f = (A &&)(A &&) A{1};     // non-const temporary expected-note {{here}}
88 
89   constexpr const A &g = {1};    // const temporary
90   constexpr A &&h = {1};         // non-const temporary expected-note {{here}}
91 
92   struct B { const A &a; };
93   B i = {{1}};           // extending decl not usable in constant expr expected-note {{here}}
94   const B j = {{1}};     // extending decl not usable in constant expr expected-note {{here}}
95   constexpr B k = {{1}}; // extending decl usable in constant expr
96 
97   static_assert(a.n == 1, "");
98   static_assert(b.n == 1, "");
99   static_assert(c.n == 1, "");
100   static_assert(d.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
101   static_assert(e.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
102   static_assert(f.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
103   static_assert(g.n == 1, "");
104   static_assert(h.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
105   static_assert(i.a.n == 1, ""); // expected-error {{constant}} expected-note {{read of non-constexpr variable}}
106   static_assert(j.a.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
107   static_assert(k.a.n == 1, "");
108 #endif
109 }
110 
111 namespace dr2140 { // dr2140: 9
112 #if __cplusplus >= 201103L
113   union U { int a; decltype(nullptr) b; };
test(U u)114   constexpr int *test(U u) {
115     return u.b;
116   }
117   static_assert(!test({123}), "u.b should be valid even when b is inactive");
118 #endif
119 }
120 
121 namespace dr2157 { // dr2157: 11
122 #if __cplusplus >= 201103L
123   enum E : int;
124   struct X {
125     enum dr2157::E : int(); // expected-error {{only allows ':' in member enumeration declaration to introduce a fixed underlying type}}
126   };
127 #endif
128 }
129 
130 namespace dr2170 { // dr2170: 9
131 #if __cplusplus >= 201103L
f()132   void f() {
133     constexpr int arr[3] = {1, 2, 3}; // expected-note {{here}}
134     struct S {
135       int get(int n) { return arr[n]; }
136       const int &get_ref(int n) { return arr[n]; } // expected-error {{enclosing function}}
137       // FIXME: expected-warning@-1 {{reference to stack}}
138     };
139   }
140 #endif
141 }
142 
143 namespace dr2180 { // dr2180: yes
144   class A {
145     A &operator=(const A &); // expected-note 0-2{{here}}
146     A &operator=(A &&); // expected-note 0-2{{here}} expected-error 0-1{{extension}}
147   };
148 
149   struct B : virtual A {
150     B &operator=(const B &);
151     B &operator=(B &&); // expected-error 0-1{{extension}}
152     virtual void foo() = 0;
153   };
154 #if __cplusplus < 201103L
155   B &B::operator=(const B&) = default; // expected-error {{private member}} expected-error {{extension}} expected-note {{here}}
156   B &B::operator=(B&&) = default; // expected-error {{private member}} expected-error 2{{extension}} expected-note {{here}}
157 #else
158   B &B::operator=(const B&) = default; // expected-error {{would delete}} expected-note@-9{{inaccessible copy assignment}}
159   B &B::operator=(B&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
160 #endif
161 }
162