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
9
9
10
10
// / Used to crash.
11
11
struct Empty {};
@@ -90,9 +90,8 @@ struct Ints2 {
90
90
int a = 10 ;
91
91
int b;
92
92
};
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}}
96
95
97
96
constexpr Ints2 I2 = Ints2{12 , 25 };
98
97
static_assert (I2.a == 12 , " " );
@@ -164,17 +163,13 @@ constexpr C RVOAndParams(int a) {
164
163
}
165
164
constexpr C RVOAndParamsResult2 = RVOAndParams(12 );
166
165
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}}
169
167
public:
170
168
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'}}
175
171
};
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}}
178
173
constexpr Bar *pb = nullptr ;
179
174
180
175
constexpr int locals () {
@@ -198,17 +193,13 @@ namespace thisPointer {
198
193
constexpr int get12 () { return 12 ; }
199
194
};
200
195
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}}
203
197
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}}
206
199
207
200
}
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()'}}
212
203
};
213
204
214
205
struct FourBoolPairs {
@@ -244,20 +235,16 @@ constexpr A a{};
244
235
static_assert (a.i == 100 , " " );
245
236
constexpr A a2{12 };
246
237
static_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'}}
251
240
252
241
253
242
struct S {
254
243
int a = 0 ;
255
244
constexpr int get5 () const { return 5 ; }
256
245
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}}
261
248
get5 ();
262
249
getInts ();
263
250
}
@@ -342,23 +329,18 @@ namespace InitializerTemporaries {
342
329
// Invalid destructor.
343
330
struct S {
344
331
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}}
351
335
};
352
336
353
337
constexpr int f () {
354
338
S{}; // ref-note {{in call to 'S{}.~S()'}}
355
339
// / FIXME: Wrong source location below.
356
340
return 12 ; // expected-note {{in call to '&S{}->~S()'}}
357
341
}
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()'}}
362
344
363
345
364
346
#endif
@@ -423,61 +405,53 @@ namespace MI {
423
405
424
406
namespace DeriveFailures {
425
407
#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}}
427
410
int Val;
428
411
};
429
412
430
413
struct Derived : Base {
431
414
int OtherVal;
432
415
433
416
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}}
436
419
};
437
420
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}}
443
424
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}} \
445
426
// ref-note {{initializer of 'D' is not a constant expression}} \
446
- // expected-error {{not an integral constant expression}} \
447
427
// expected-note {{read of uninitialized object}}
448
428
#endif
449
429
450
430
struct AnotherBase {
451
431
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}}
454
433
};
455
434
456
435
struct AnotherDerived : AnotherBase {
457
436
constexpr AnotherDerived (int i) : AnotherBase(i) {}
458
437
};
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)'}}
463
440
464
441
struct YetAnotherBase {
465
442
int Val;
466
443
constexpr YetAnotherBase (int i) : Val(i) {}
467
444
};
468
445
469
446
struct YetAnotherDerived : YetAnotherBase {
470
- using YetAnotherBase::YetAnotherBase; // ref-note {{declared here}} \
471
- // expected-note {{declared here}}
447
+ using YetAnotherBase::YetAnotherBase; // both-note {{declared here}}
472
448
int OtherVal;
473
449
474
450
constexpr bool doit () const { return Val == OtherVal; }
475
451
};
476
452
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}}
481
455
};
482
456
483
457
namespace EmptyCtor {
@@ -543,18 +517,10 @@ namespace PointerArith {
543
517
constexpr B *b1 = &b + 1 ;
544
518
constexpr B *b2 = &b + 0 ;
545
519
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}}
558
524
}
559
525
560
526
#if __cplusplus >= 202002L
@@ -632,23 +598,18 @@ namespace Destructors {
632
598
633
599
struct S {
634
600
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}}
641
604
}
642
605
};
643
606
constexpr int testS () {
644
607
S{}; // ref-note {{in call to 'S{}.~S()'}}
645
608
return 1 ; // expected-note {{in call to '&S{}->~S()'}}
646
609
// FIXME: ^ Wrong line
647
610
}
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()'}}
652
613
}
653
614
654
615
namespace BaseToDerived {
@@ -657,10 +618,8 @@ namespace A {
657
618
struct B : A { int n; };
658
619
struct C : B {};
659
620
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}}
664
623
}
665
624
namespace B {
666
625
struct A {};
@@ -894,10 +853,8 @@ namespace VirtualFromBase {
894
853
// Virtual f(), not OK.
895
854
constexpr X<X<S2>> xxs2;
896
855
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}}
901
858
}
902
859
#endif
903
860
@@ -1070,14 +1027,10 @@ namespace ParenInit {
1070
1027
1071
1028
// / Not constexpr!
1072
1029
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}}
1081
1034
}
1082
1035
#endif
1083
1036
@@ -1109,32 +1062,24 @@ namespace AccessOnNullptr {
1109
1062
int a;
1110
1063
};
1111
1064
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}}
1114
1066
F *f = nullptr ;
1115
1067
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}}
1118
1069
return f->a ;
1119
1070
}
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()'}}
1124
1073
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}}
1127
1075
F *f = nullptr ;
1128
1076
1129
1077
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}}
1132
1079
return f->a ;
1133
1080
}
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()'}}
1138
1083
}
1139
1084
1140
1085
namespace IndirectFieldInit {
0 commit comments