|
2 | 2 | // RUN: %clang_cc1 -fsyntax-only -Wall -Wc++20-compat -Wuninitialized -Wno-unused-value -Wno-unused-lambda-capture -Wno-uninitialized-const-reference -std=c++1z -verify %s -fexperimental-new-constant-interpreter
|
3 | 3 | // RUN: %clang_cc1 -fsyntax-only -Wall -Wc++20-compat -Wuninitialized -Wno-unused-value -Wno-unused-lambda-capture -Wno-uninitialized-const-reference -std=c++20 -verify %s
|
4 | 4 |
|
| 5 | +void* operator new(__SIZE_TYPE__, void*); |
| 6 | + |
5 | 7 | // definitions for std::move
|
6 | 8 | namespace std {
|
7 | 9 | inline namespace foo {
|
@@ -1540,6 +1542,48 @@ void aggregate() {
|
1540 | 1542 | };
|
1541 | 1543 | };
|
1542 | 1544 |
|
| 1545 | + struct Embed { |
| 1546 | + int embed1; // #FIELD_EMBED1 |
| 1547 | + int embed2 [[clang::require_explicit_initialization]]; // #FIELD_EMBED2 |
| 1548 | + }; |
| 1549 | + struct EmbedDerived : Embed {}; |
| 1550 | + struct F { |
| 1551 | + Embed f1; |
| 1552 | + // expected-warning@+1 {{field in 'Embed' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1553 | + explicit F(const char(&)[1]) : f1() { |
| 1554 | + // expected-warning@+1 {{field in 'Embed' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1555 | + ::new(static_cast<void*>(&f1)) decltype(f1); |
| 1556 | + // expected-warning@+1 {{field in 'Embed' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1557 | + ::new(static_cast<void*>(&f1)) decltype(f1)(); |
| 1558 | +#if __cplusplus >= 202002L |
| 1559 | + // expected-warning@+1 {{field 'embed2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1560 | + ::new(static_cast<void*>(&f1)) decltype(f1)(1); |
| 1561 | +#endif |
| 1562 | + // expected-warning@+1 {{field 'embed2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1563 | + ::new(static_cast<void*>(&f1)) decltype(f1){1}; |
| 1564 | + } |
| 1565 | +#if __cplusplus >= 202002L |
| 1566 | + // expected-warning@+1 {{field 'embed2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1567 | + explicit F(const char(&)[2]) : f1(1) {} |
| 1568 | +#else |
| 1569 | + explicit F(const char(&)[2]) : f1{1, 2} { } |
| 1570 | +#endif |
| 1571 | + // expected-warning@+1 {{field 'embed2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1572 | + explicit F(const char(&)[3]) : f1{} {} |
| 1573 | + // expected-warning@+1 {{field 'embed2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1574 | + explicit F(const char(&)[4]) : f1{1} {} |
| 1575 | + // expected-warning@+1 {{field 'embed2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' declared here}} |
| 1576 | + explicit F(const char(&)[5]) : f1{.embed1 = 1} {} |
| 1577 | + }; |
| 1578 | + F ctors[] = { |
| 1579 | + F(""), |
| 1580 | + F("_"), |
| 1581 | + F("__"), |
| 1582 | + F("___"), |
| 1583 | + F("____") |
| 1584 | + }; |
| 1585 | + (void)ctors; |
| 1586 | + |
1543 | 1587 | S::foo(S{1, 2, 3, 4});
|
1544 | 1588 | S::foo(S{.s1 = 100, .s4 = 100});
|
1545 | 1589 | S::foo(S{.s1 = 100}); // expected-warning {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
|
|
0 commit comments