Skip to content

Commit eb073da

Browse files
Error message improvements
1 parent 44961d2 commit eb073da

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,9 +2319,10 @@ def warn_cxx20_compat_aggregate_init_with_ctors : Warning<
23192319
"aggregate initialization of type %0 with user-declared constructors "
23202320
"is incompatible with C++20">, DefaultIgnore, InGroup<CXX20Compat>;
23212321
def warn_cxx20_compat_requires_explicit_init_non_aggregate : Warning<
2322-
"explicit initialization of field %0 may not be enforced in C++20 as type %1 "
2323-
"will become a non-aggregate due to the presence of user-declared "
2324-
"constructors">, DefaultIgnore, InGroup<CXX20Compat>;
2322+
"explicit initialization of field %0 will not be enforced in C++20 and later "
2323+
"because %1 has a user-declared constructor, making the type no longer an "
2324+
"aggregate">,
2325+
DefaultIgnore, InGroup<CXX20Compat>;
23252326
def warn_cxx17_compat_aggregate_init_paren_list : Warning<
23262327
"aggregate initialization of type %0 from a parenthesized list of values "
23272328
"is a C++20 extension">, DefaultIgnore, InGroup<CXX20>;
@@ -2352,8 +2353,8 @@ def err_init_reference_member_uninitialized : Error<
23522353
def note_uninit_reference_member : Note<
23532354
"uninitialized reference member is here">;
23542355
def warn_field_requires_explicit_init : Warning<
2355-
"field %select{%1|in %1}0 is not explicitly initialized, but was marked as "
2356-
"requiring explicit initialization">, InGroup<UninitializedExplicitInit>;
2356+
"field %select{%1|in %1}0 requires explicit initialization but is not "
2357+
"explicitly initialized">, InGroup<UninitializedExplicitInit>;
23572358
def warn_field_is_uninit : Warning<"field %0 is uninitialized when used here">,
23582359
InGroup<Uninitialized>;
23592360
def warn_base_class_is_uninit : Warning<

clang/test/Sema/uninit-variables.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ struct with_explicit_field {
558558
};
559559

560560
void aggregate() {
561-
struct with_explicit_field a; // expected-warning {{field in 'with_explicit_field' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_Y {{'y' declared here}}
562-
struct with_explicit_field b = {1}; // expected-warning {{field 'y' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_Y {{'y' declared here}}
561+
struct with_explicit_field a; // expected-warning {{field in 'with_explicit_field' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_Y {{'y' declared here}}
562+
struct with_explicit_field b = {1}; // expected-warning {{field 'y' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_Y {{'y' declared here}}
563563
(void)(&a != &b);
564564
}

clang/test/SemaCXX/uninitialized.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,62 +1513,62 @@ void aggregate() {
15131513

15141514
S::foo(S{1, 2, 3, 4});
15151515
S::foo(S{.s1 = 100, .s4 = 100});
1516-
S::foo(S{.s1 = 100}); // expected-warning {{field 's4' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S4 {{'s4' declared here}}
1516+
S::foo(S{.s1 = 100}); // expected-warning {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
15171517

15181518
S s{.s1 = 100, .s4 = 100};
15191519
(void)s;
15201520

1521-
S t{.s4 = 100}; // expected-warning {{field 's1' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S1 {{'s1' declared here}}
1521+
S t{.s4 = 100}; // expected-warning {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
15221522
(void)t;
15231523

1524-
S *ptr1 = new S; // expected-warning {{field in 'S' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S4 {{'s4' declared here}} expected-note@#FIELD_S1 {{'s1' declared here}}
1524+
S *ptr1 = new S; // expected-warning {{field in 'S' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}} expected-note@#FIELD_S1 {{'s1' declared here}}
15251525
delete ptr1;
15261526

15271527
S *ptr2 = new S{.s1 = 100, .s4 = 100};
15281528
delete ptr2;
15291529

15301530
#if __cplusplus >= 202002L
1531-
// expected-warning@+2 {{field 'd2' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_D2 {{'d2' declared here}}
1532-
// expected-warning {{field 's1' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S1 {{'s1' declared here}}
1531+
// expected-warning@+2 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1532+
// expected-warning {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
15331533
D a({}, 0);
15341534
(void)a;
15351535
#else
1536-
C a; // expected-warning {{field in 'C' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_C1 {{'c1' declared here}}
1536+
C a; // expected-warning {{field in 'C' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_C1 {{'c1' declared here}}
15371537
(void)a;
15381538
#endif
15391539

1540-
// expected-warning@+2 {{field 's4' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S4 {{'s4' declared here}}
1541-
// expected-warning@+1 {{field 's1' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S1 {{'s1' declared here}}
1540+
// expected-warning@+2 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1541+
// expected-warning@+1 {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
15421542
D b{.d2 = 1};
15431543
(void)b;
15441544

1545-
// expected-warning@+3 {{field 's4' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S4 {{'s4' declared here}}
1546-
// expected-warning@+2 {{field 'd2' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_D2 {{'d2' declared here}}
1547-
// expected-warning@+1 {{field 's1' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S1 {{'s1' declared here}}
1545+
// expected-warning@+3 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1546+
// expected-warning@+2 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1547+
// expected-warning@+1 {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
15481548
D c{.d1 = 5};
15491549

1550-
// expected-warning@+3 {{field 's4' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S4 {{'s4' declared here}}
1551-
// expected-warning@+2 {{field 'd2' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_D2 {{'d2' declared here}}
1552-
// expected-warning@+1 {{field 's1' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S1 {{'s1' declared here}}
1550+
// expected-warning@+3 {{field 's4' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S4 {{'s4' declared here}}
1551+
// expected-warning@+2 {{field 'd2' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
1552+
// expected-warning@+1 {{field 's1' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}}
15531553
c = {{}, 0};
15541554
(void)c;
15551555

15561556
// expected-note@+3 {{in implicit default constructor for 'D' first required here}}
1557-
// expected-warning@#TYPE_D {{field in 'S' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_S1 {{'s1' declared here}} expected-note@#FIELD_S4 {{'s4' declared here}}
1558-
// expected-warning@+1 {{field in 'D' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_D2 {{'d2' declared here}}
1557+
// expected-warning@#TYPE_D {{field in 'S' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_S1 {{'s1' declared here}} expected-note@#FIELD_S4 {{'s4' declared here}}
1558+
// expected-warning@+1 {{field in 'D' requires explicit initialization but is not explicitly initialized}} expected-note@#FIELD_D2 {{'d2' declared here}}
15591559
D d;
15601560
(void)d;
15611561

1562-
// expected-warning@+12 {{field in 'E' is not explicitly initialized, but was marked as requiring explicit initialization}}
1562+
// expected-warning@+12 {{field in 'E' requires explicit initialization but is not explicitly initialized}}
15631563
// expected-note@#FIELD_E2 {{'e2' declared here}}
1564-
// expected-warning@#TYPE_E {{field in 'D' is not explicitly initialized, but was marked as requiring explicit initialization}}
1564+
// expected-warning@#TYPE_E {{field in 'D' requires explicit initialization but is not explicitly initialized}}
15651565
// expected-note@+9 {{in implicit default constructor for 'E' first required here}}
15661566
// expected-note@#FIELD_D2 {{'d2' declared here}}
1567-
// expected-warning@#TYPE_E {{field in 'D' is not explicitly initialized, but was marked as requiring explicit initialization}}
1567+
// expected-warning@#TYPE_E {{field in 'D' requires explicit initialization but is not explicitly initialized}}
15681568
// expected-note@#FIELD_D2 {{'d2' declared here}}
1569-
// expected-warning@#TYPE_E {{field in 'D2' is not explicitly initialized, but was marked as requiring explicit initialization}}
1569+
// expected-warning@#TYPE_E {{field in 'D2' requires explicit initialization but is not explicitly initialized}}
15701570
// expected-note@#TYPE_E {{in implicit default constructor for 'D2' first required here}}
1571-
// expected-warning@#TYPE_D2 {{field in 'D' is not explicitly initialized, but was marked as requiring explicit initialization}}
1571+
// expected-warning@#TYPE_D2 {{field in 'D' requires explicit initialization but is not explicitly initialized}}
15721572
// expected-note@+2 {{in implicit default constructor for 'E' first required here}}
15731573
// expected-note@#FIELD_D2 {{'d2' declared here}}
15741574
E e;

0 commit comments

Comments
 (0)