Skip to content

Commit 2f7067f

Browse files
More fixes
1 parent 23bb234 commit 2f7067f

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ def warn_attribute_needs_aggregate : Warning<
395395
InGroup<IgnoredAttributes>;
396396

397397
def warn_cxx20_compat_requires_explicit_init_non_aggregate : Warning<
398-
"explicit initialization of field %0 will not be enforced in C++20 and later "
399-
"because %1 has a user-declared constructor, making the type no longer an "
398+
"explicit initialization of field %1 will not be enforced in C++20 and later "
399+
"because %2 has a user-declared constructor, making the type no longer an "
400400
"aggregate">,
401401
DefaultIgnore, InGroup<CXX20Compat>;
402402

clang/lib/AST/DeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) {
22112211
Context.getDiagnostics().Report(
22122212
AT->getLocation(),
22132213
diag::warn_cxx20_compat_requires_explicit_init_non_aggregate)
2214-
<< AT << Context.getRecordType(this);
2214+
<< AT << FD << Context.getRecordType(this);
22152215
}
22162216
}
22172217

clang/test/SemaCXX/uninitialized.cpp

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// RUN: %clang_cc1 -fsyntax-only -Wall -Wuninitialized -Wno-unused-value -Wno-unused-lambda-capture -Wno-uninitialized-const-reference -std=c++1z -verify %s
2-
// RUN: %clang_cc1 -fsyntax-only -Wall -Wuninitialized -Wno-unused-value -Wno-unused-lambda-capture -Wno-uninitialized-const-reference -std=c++1z -verify %s -fexperimental-new-constant-interpreter
1+
// 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
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+
// 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
34

45
// definitions for std::move
56
namespace std {
@@ -1514,10 +1515,11 @@ void aggregate() {
15141515
};
15151516

15161517
struct C {
1517-
[[clang::requires_explicit_initialization]] int c1; // #FIELD_C1
1518-
#if 201703L <= __cplusplus && __cplusplus < 202002L
1519-
// expected-warning@#FIELD_C1 {{explicit initialization of field 'c1' will not be enforced in C++20 and later because 'C' has a user-declared constructor, making the type no longer an aggregate}}
1518+
#if __cplusplus < 202002L
1519+
// expected-warning@+1 {{explicit initialization of field 'c1' will not be enforced in C++20 and later because 'C' has a user-declared constructor, making the type no longer an aggregate}}
1520+
[[clang::requires_explicit_initialization]]
15201521
#endif
1522+
int c1; // #FIELD_C1
15211523
C() = default; // Test pre-C++20 aggregates
15221524
};
15231525

@@ -1555,11 +1557,41 @@ void aggregate() {
15551557
delete ptr2;
15561558

15571559
#if __cplusplus >= 202002L
1558-
// expected-warning@+2 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1559-
// expected-warning {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
1560-
D a({}, 0);
1561-
(void)a;
1562-
#else
1560+
// expected-warning@+3 {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
1561+
// expected-warning@+2 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1562+
// expected-warning@+1 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1563+
D a1({}, 0);
1564+
(void)a1;
1565+
1566+
// expected-warning@+3 {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
1567+
// expected-warning@+2 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1568+
// expected-warning@+1 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1569+
D a2(S{}, 0);
1570+
(void)a2;
1571+
1572+
// expected-warning@+2 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1573+
// expected-warning@+1 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1574+
D a3(S{.s1 = 0}, 0);
1575+
(void)a3;
1576+
1577+
// expected-warning@+3 {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
1578+
// expected-warning@+2 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1579+
// expected-warning@+1 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1580+
D a4(S(), 0);
1581+
(void)a4;
1582+
1583+
// expected-warning@+2 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1584+
// expected-warning@+1 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1585+
D a5(S(0), 0);
1586+
(void)a5;
1587+
1588+
// expected-warning@+2 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1589+
// expected-warning@+1 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1590+
D a6 = {S(0), 0};
1591+
(void)a6;
1592+
#endif
1593+
1594+
#if 201103L <= __cplusplus && __cplusplus < 202002L
15631595
C a; // expected-warning {{field in 'C' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_C1 {{'c1' declared here}}
15641596
(void)a;
15651597
#endif

0 commit comments

Comments
 (0)