1- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
2- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify %s
3- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
4- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 -verify %s
5- // RUN: %clang_cc1 -verify=ref %s
6- // RUN: %clang_cc1 -verify=ref -std=c++14 %s
7- // RUN: %clang_cc1 -verify=ref -std=c++20 %s
8- // RUN: %clang_cc1 -verify=ref -triple i686 %s
1+ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both %s
2+ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++14 -verify=expected,both %s
3+ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify=expected,both %s
4+ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple i686 -verify=expected,both %s
5+ // RUN: %clang_cc1 -verify=ref,both %s
6+ // RUN: %clang_cc1 -verify=ref,both -std=c++14 %s
7+ // RUN: %clang_cc1 -verify=ref,both -std=c++20 %s
8+ // RUN: %clang_cc1 -verify=ref,both -triple i686 %s
99
1010// / Used to crash.
1111struct Empty {};
@@ -90,9 +90,8 @@ struct Ints2 {
9090 int a = 10 ;
9191 int b;
9292};
93- constexpr Ints2 ints22; // expected-error {{without a user-provided default constructor}} \
94- // expected-error {{must be initialized by a constant expression}} \
95- // ref-error {{without a user-provided default constructor}}
93+ constexpr Ints2 ints22; // both-error {{without a user-provided default constructor}} \
94+ // expected-error {{must be initialized by a constant expression}}
9695
9796constexpr Ints2 I2 = Ints2{12 , 25 };
9897static_assert (I2.a == 12 , " " );
@@ -164,17 +163,13 @@ constexpr C RVOAndParams(int a) {
164163}
165164constexpr C RVOAndParamsResult2 = RVOAndParams(12 );
166165
167- class Bar { // expected-note {{definition of 'Bar' is not complete}} \
168- // ref-note {{definition of 'Bar' is not complete}}
166+ class Bar { // both-note {{definition of 'Bar' is not complete}}
169167public:
170168 constexpr Bar (){}
171- constexpr Bar b; // expected-error {{cannot be constexpr}} \
172- // expected-error {{has incomplete type 'const Bar'}} \
173- // ref-error {{cannot be constexpr}} \
174- // ref-error {{has incomplete type 'const Bar'}}
169+ constexpr Bar b; // both-error {{cannot be constexpr}} \
170+ // both-error {{has incomplete type 'const Bar'}}
175171};
176- constexpr Bar B; // expected-error {{must be initialized by a constant expression}} \
177- // ref-error {{must be initialized by a constant expression}}
172+ constexpr Bar B; // both-error {{must be initialized by a constant expression}}
178173constexpr Bar *pb = nullptr ;
179174
180175constexpr int locals () {
@@ -198,17 +193,13 @@ namespace thisPointer {
198193 constexpr int get12 () { return 12 ; }
199194 };
200195
201- constexpr int foo () { // ref-error {{never produces a constant expression}} \
202- // expected-error {{never produces a constant expression}}
196+ constexpr int foo () { // both-error {{never produces a constant expression}}
203197 S *s = nullptr ;
204- return s->get12 (); // ref-note 2{{member call on dereferenced null pointer}} \
205- // expected-note 2{{member call on dereferenced null pointer}}
198+ return s->get12 (); // both-note 2{{member call on dereferenced null pointer}}
206199
207200 }
208- static_assert (foo() == 12 , " " ); // ref-error {{not an integral constant expression}} \
209- // ref-note {{in call to 'foo()'}} \
210- // expected-error {{not an integral constant expression}} \
211- // expected-note {{in call to 'foo()'}}
201+ static_assert (foo() == 12 , " " ); // both-error {{not an integral constant expression}} \
202+ // both-note {{in call to 'foo()'}}
212203};
213204
214205struct FourBoolPairs {
@@ -244,20 +235,16 @@ constexpr A a{};
244235static_assert (a.i == 100 , " " );
245236constexpr A a2{12 };
246237static_assert (a2.i == 12 , " " );
247- static_assert (a2.i == 200 , " " ); // ref-error {{static assertion failed}} \
248- // ref-note {{evaluates to '12 == 200'}} \
249- // expected-error {{static assertion failed}} \
250- // expected-note {{evaluates to '12 == 200'}}
238+ static_assert (a2.i == 200 , " " ); // both-error {{static assertion failed}} \
239+ // both-note {{evaluates to '12 == 200'}}
251240
252241
253242struct S {
254243 int a = 0 ;
255244 constexpr int get5 () const { return 5 ; }
256245 constexpr void fo () const {
257- this ; // expected-warning {{expression result unused}} \
258- // ref-warning {{expression result unused}}
259- this ->a ; // expected-warning {{expression result unused}} \
260- // ref-warning {{expression result unused}}
246+ this ; // both-warning {{expression result unused}}
247+ this ->a ; // both-warning {{expression result unused}}
261248 get5 ();
262249 getInts ();
263250 }
@@ -342,23 +329,18 @@ namespace InitializerTemporaries {
342329 // Invalid destructor.
343330 struct S {
344331 constexpr S () {}
345- constexpr ~S () noexcept (false ) { throw 12 ; } // expected-error {{cannot use 'throw'}} \
346- // expected-error {{never produces a constant expression}} \
347- // expected-note 2{{subexpression not valid}} \
348- // ref-error {{cannot use 'throw'}} \
349- // ref-error {{never produces a constant expression}} \
350- // ref-note 2{{subexpression not valid}}
332+ constexpr ~S () noexcept (false ) { throw 12 ; } // both-error {{cannot use 'throw'}} \
333+ // both-error {{never produces a constant expression}} \
334+ // both-note 2{{subexpression not valid}}
351335 };
352336
353337 constexpr int f () {
354338 S{}; // ref-note {{in call to 'S{}.~S()'}}
355339 // / FIXME: Wrong source location below.
356340 return 12 ; // expected-note {{in call to '&S{}->~S()'}}
357341 }
358- static_assert (f() == 12); // expected-error {{not an integral constant expression}} \
359- // expected-note {{in call to 'f()'}} \
360- // ref-error {{not an integral constant expression}} \
361- // ref-note {{in call to 'f()'}}
342+ static_assert (f() == 12); // both-error {{not an integral constant expression}} \
343+ // both-note {{in call to 'f()'}}
362344
363345
364346#endif
@@ -423,61 +405,53 @@ namespace MI {
423405
424406namespace DeriveFailures {
425407#if __cplusplus < 202002L
426- struct Base { // ref-note 2{{declared here}} expected-note {{declared here}}
408+ struct Base { // both-note {{declared here}} \
409+ // ref-note {{declared here}}
427410 int Val;
428411 };
429412
430413 struct Derived : Base {
431414 int OtherVal;
432415
433416 constexpr Derived (int i) : OtherVal(i) {} // ref-error {{never produces a constant expression}} \
434- // ref -note 2 {{non-constexpr constructor 'Base' cannot be used in a constant expression}} \
435- // expected -note {{non-constexpr constructor 'Base' cannot be used in a constant expression}}
417+ // both -note {{non-constexpr constructor 'Base' cannot be used in a constant expression}} \
418+ // ref -note {{non-constexpr constructor 'Base' cannot be used in a constant expression}}
436419 };
437420
438- constexpr Derived D (12 ); // ref-error {{must be initialized by a constant expression}} \
439- // ref-note {{in call to 'Derived(12)'}} \
440- // ref-note {{declared here}} \
441- // expected-error {{must be initialized by a constant expression}} \
442- // expected-note {{in call to 'Derived(12)'}}
421+ constexpr Derived D (12 ); // both-error {{must be initialized by a constant expression}} \
422+ // both-note {{in call to 'Derived(12)'}} \
423+ // ref-note {{declared here}}
443424
444- static_assert (D.Val == 0 , " " ); // ref -error {{not an integral constant expression}} \
425+ static_assert (D.Val == 0 , " " ); // both -error {{not an integral constant expression}} \
445426 // ref-note {{initializer of 'D' is not a constant expression}} \
446- // expected-error {{not an integral constant expression}} \
447427 // expected-note {{read of uninitialized object}}
448428#endif
449429
450430 struct AnotherBase {
451431 int Val;
452- constexpr AnotherBase (int i) : Val(12 / i) {} // ref-note {{division by zero}} \
453- //expected-note {{division by zero}}
432+ constexpr AnotherBase (int i) : Val(12 / i) {} // both-note {{division by zero}}
454433 };
455434
456435 struct AnotherDerived : AnotherBase {
457436 constexpr AnotherDerived (int i) : AnotherBase(i) {}
458437 };
459- constexpr AnotherBase Derp (0 ); // ref-error {{must be initialized by a constant expression}} \
460- // ref-note {{in call to 'AnotherBase(0)'}} \
461- // expected-error {{must be initialized by a constant expression}} \
462- // expected-note {{in call to 'AnotherBase(0)'}}
438+ constexpr AnotherBase Derp (0 ); // both-error {{must be initialized by a constant expression}} \
439+ // both-note {{in call to 'AnotherBase(0)'}}
463440
464441 struct YetAnotherBase {
465442 int Val;
466443 constexpr YetAnotherBase (int i) : Val(i) {}
467444 };
468445
469446 struct YetAnotherDerived : YetAnotherBase {
470- using YetAnotherBase::YetAnotherBase; // ref-note {{declared here}} \
471- // expected-note {{declared here}}
447+ using YetAnotherBase::YetAnotherBase; // both-note {{declared here}}
472448 int OtherVal;
473449
474450 constexpr bool doit () const { return Val == OtherVal; }
475451 };
476452
477- constexpr YetAnotherDerived Oops (0 ); // ref-error {{must be initialized by a constant expression}} \
478- // ref-note {{constructor inherited from base class 'YetAnotherBase' cannot be used in a constant expression}} \
479- // expected-error {{must be initialized by a constant expression}} \
480- // expected-note {{constructor inherited from base class 'YetAnotherBase' cannot be used in a constant expression}}
453+ constexpr YetAnotherDerived Oops (0 ); // both-error {{must be initialized by a constant expression}} \
454+ // both-note {{constructor inherited from base class 'YetAnotherBase' cannot be used in a constant expression}}
481455};
482456
483457namespace EmptyCtor {
@@ -543,18 +517,10 @@ namespace PointerArith {
543517 constexpr B *b1 = &b + 1 ;
544518 constexpr B *b2 = &b + 0 ;
545519
546- #if 0
547- constexpr A *a2 = &b + 1; // expected-error {{must be initialized by a constant expression}} \
548- // expected-note {{cannot access base class of pointer past the end of object}} \
549- // ref-error {{must be initialized by a constant expression}} \
550- // ref-note {{cannot access base class of pointer past the end of object}}
551-
552- #endif
553- constexpr const int *pn = &(&b + 1 )->n; // expected-error {{must be initialized by a constant expression}} \
554- // expected-note {{cannot access field of pointer past the end of object}} \
555- // ref-error {{must be initialized by a constant expression}} \
556- // ref-note {{cannot access field of pointer past the end of object}}
557-
520+ constexpr A *a2 = &b + 1 ; // both-error {{must be initialized by a constant expression}} \
521+ // both-note {{cannot access base class of pointer past the end of object}}
522+ constexpr const int *pn = &(&b + 1 )->n; // both-error {{must be initialized by a constant expression}} \
523+ // both-note {{cannot access field of pointer past the end of object}}
558524}
559525
560526#if __cplusplus >= 202002L
@@ -632,23 +598,18 @@ namespace Destructors {
632598
633599 struct S {
634600 constexpr S () {}
635- constexpr ~S () { // expected-error {{never produces a constant expression}} \
636- // ref-error {{never produces a constant expression}}
637- int i = 1 / 0 ; // expected-warning {{division by zero}} \
638- // expected-note 2{{division by zero}} \
639- // ref-warning {{division by zero}} \
640- // ref-note 2{{division by zero}}
601+ constexpr ~S () { // both-error {{never produces a constant expression}}
602+ int i = 1 / 0 ; // both-warning {{division by zero}} \
603+ // both-note 2{{division by zero}}
641604 }
642605 };
643606 constexpr int testS () {
644607 S{}; // ref-note {{in call to 'S{}.~S()'}}
645608 return 1 ; // expected-note {{in call to '&S{}->~S()'}}
646609 // FIXME: ^ Wrong line
647610 }
648- static_assert (testS() == 1 ); // expected-error {{not an integral constant expression}} \
649- // expected-note {{in call to 'testS()'}} \
650- // ref-error {{not an integral constant expression}} \
651- // ref-note {{in call to 'testS()'}}
611+ static_assert (testS() == 1 ); // both-error {{not an integral constant expression}} \
612+ // both-note {{in call to 'testS()'}}
652613}
653614
654615namespace BaseToDerived {
@@ -657,10 +618,8 @@ namespace A {
657618 struct B : A { int n; };
658619 struct C : B {};
659620 C c = {};
660- constexpr C *pb = (C*)((A*)&c + 1 ); // expected-error {{must be initialized by a constant expression}} \
661- // expected-note {{cannot access derived class of pointer past the end of object}} \
662- // ref-error {{must be initialized by a constant expression}} \
663- // ref-note {{cannot access derived class of pointer past the end of object}}
621+ constexpr C *pb = (C*)((A*)&c + 1 ); // both-error {{must be initialized by a constant expression}} \
622+ // both-note {{cannot access derived class of pointer past the end of object}}
664623}
665624namespace B {
666625 struct A {};
@@ -894,10 +853,8 @@ namespace VirtualFromBase {
894853 // Virtual f(), not OK.
895854 constexpr X<X<S2>> xxs2;
896855 constexpr X<S2> *q = const_cast <X<X<S2>>*>(&xxs2);
897- static_assert (q->f () == sizeof(X<S2>), ""); // ref-error {{not an integral constant expression}} \
898- // ref-note {{cannot evaluate call to virtual function}} \
899- // expected-error {{not an integral constant expression}} \
900- // expected-note {{cannot evaluate call to virtual function}}
856+ static_assert (q->f () == sizeof(X<S2>), ""); // both-error {{not an integral constant expression}} \
857+ // both-note {{cannot evaluate call to virtual function}}
901858}
902859#endif
903860
@@ -1070,14 +1027,10 @@ namespace ParenInit {
10701027
10711028 // / Not constexpr!
10721029 O o1 (0 );
1073- constinit O o2 (0 ); // ref-error {{variable does not have a constant initializer}} \
1074- // ref-note {{required by 'constinit' specifier}} \
1075- // ref-note {{reference to temporary is not a constant expression}} \
1076- // ref-note {{temporary created here}} \
1077- // expected-error {{variable does not have a constant initializer}} \
1078- // expected-note {{required by 'constinit' specifier}} \
1079- // expected-note {{reference to temporary is not a constant expression}} \
1080- // expected-note {{temporary created here}}
1030+ constinit O o2 (0 ); // both-error {{variable does not have a constant initializer}} \
1031+ // both-note {{required by 'constinit' specifier}} \
1032+ // both-note {{reference to temporary is not a constant expression}} \
1033+ // both-note {{temporary created here}}
10811034}
10821035#endif
10831036
@@ -1109,32 +1062,24 @@ namespace AccessOnNullptr {
11091062 int a;
11101063 };
11111064
1112- constexpr int a () { // expected-error {{never produces a constant expression}} \
1113- // ref-error {{never produces a constant expression}}
1065+ constexpr int a () { // both-error {{never produces a constant expression}}
11141066 F *f = nullptr ;
11151067
1116- f->a = 0 ; // expected-note 2{{cannot access field of null pointer}} \
1117- // ref-note 2{{cannot access field of null pointer}}
1068+ f->a = 0 ; // both-note 2{{cannot access field of null pointer}}
11181069 return f->a ;
11191070 }
1120- static_assert (a() == 0 , " " ); // expected-error {{not an integral constant expression}} \
1121- // expected-note {{in call to 'a()'}} \
1122- // ref-error {{not an integral constant expression}} \
1123- // ref-note {{in call to 'a()'}}
1071+ static_assert (a() == 0 , " " ); // both-error {{not an integral constant expression}} \
1072+ // both-note {{in call to 'a()'}}
11241073
1125- constexpr int a2 () { // expected-error {{never produces a constant expression}} \
1126- // ref-error {{never produces a constant expression}}
1074+ constexpr int a2 () { // both-error {{never produces a constant expression}}
11271075 F *f = nullptr ;
11281076
11291077
1130- const int *a = &(f->a ); // expected-note 2{{cannot access field of null pointer}} \
1131- // ref-note 2{{cannot access field of null pointer}}
1078+ const int *a = &(f->a ); // both-note 2{{cannot access field of null pointer}}
11321079 return f->a ;
11331080 }
1134- static_assert (a2() == 0 , " " ); // expected-error {{not an integral constant expression}} \
1135- // expected-note {{in call to 'a2()'}} \
1136- // ref-error {{not an integral constant expression}} \
1137- // ref-note {{in call to 'a2()'}}
1081+ static_assert (a2() == 0 , " " ); // both-error {{not an integral constant expression}} \
1082+ // both-note {{in call to 'a2()'}}
11381083}
11391084
11401085namespace IndirectFieldInit {
0 commit comments