Skip to content

Commit d3bd0ec

Browse files
Improve tests
1 parent c2b9dae commit d3bd0ec

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,8 @@ initializers exist):
16401640
}, {
16411641
.count = sizeof(buf) / sizeof(*buf),
16421642
// warning: field 'element_size' is not explicitly initialized
1643+
// (Note that a missing initializer for 'flags' is not diagnosed, because
1644+
// the field is not marked as requiring explicit initialization.)
16431645
});
16441646
}
16451647

clang/test/Sema/uninit-variables.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,26 @@ struct with_explicit_field {
557557
int y [[clang::requires_explicit_initialization]]; // #FIELD_Y
558558
};
559559

560+
struct with_explicit_array {
561+
int arr[2] [[clang::requires_explicit_initialization]]; // #FIELD_ARR
562+
};
563+
564+
struct with_explicit_flex_array {
565+
int flex_arr[] [[clang::requires_explicit_initialization]]; // #FIELD_FLEX_ARR
566+
};
567+
560568
void aggregate() {
561569
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}}
562570
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}}
563571
(void)(&a != &b);
572+
573+
struct with_explicit_field c = {1, 2};
574+
struct with_explicit_field d = {.y = 3};
575+
(void)(&c != &d);
576+
577+
struct with_explicit_array e = {{1}}; // OK -- part of array is still initialized
578+
(void)e;
579+
580+
struct with_explicit_array f = {}; // expected-warning {{field 'flex_arr' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_FLEX_ARR {{'flex_arr' declared here}}
581+
(void)f;
564582
}

clang/test/SemaCXX/uninitialized.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,30 @@ template<typename T> struct Outer {
14731473
};
14741474
Outer<int>::Inner outerinner;
14751475

1476+
struct Polymorphic { virtual ~Polymorphic() { } };
1477+
1478+
template<class... Bases>
1479+
struct Inherit : Bases... { // #TYPE_INHERIT
1480+
int g1; // #FIELD_G1
1481+
};
1482+
1483+
template<class... Bases>
1484+
struct InheritWithExplicit : Bases... { // #TYPE_INHERIT_WITH_EXPLICIT
1485+
int g2 [[clang::requires_explicit_initialization]]; // #FIELD_G2
1486+
};
1487+
1488+
struct Special {};
1489+
1490+
template<>
1491+
struct Inherit<Special> {
1492+
int g3 [[clang::requires_explicit_initialization]]; // #FIELD_G3
1493+
};
1494+
1495+
template<>
1496+
struct InheritWithExplicit<Special> {
1497+
int g4; // #FIELD_G4
1498+
};
1499+
14761500
void aggregate() {
14771501
struct NonAgg {
14781502
NonAgg() { }
@@ -1490,7 +1514,7 @@ void aggregate() {
14901514
};
14911515

14921516
struct C {
1493-
[[clang::requires_explicit_initialization]] int c1 = 2; // #FIELD_C1
1517+
[[clang::requires_explicit_initialization]] int c1; // #FIELD_C1
14941518
C() = default; // Test pre-C++20 aggregates
14951519
};
14961520

@@ -1573,4 +1597,18 @@ void aggregate() {
15731597
// expected-note@#FIELD_D2 {{'d2' declared here}}
15741598
E e;
15751599
(void)e;
1600+
1601+
InheritWithExplicit<> agg;
1602+
(void)agg;
1603+
// expected-warning@#TYPE_INHERIT_WITH_EXPLICIT {{field in 'InheritWithExplicit<>' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_G2 {{'g2' declared here}}
1604+
1605+
InheritWithExplicit<Polymorphic> polymorphic; // no-warning
1606+
(void)polymorphic;
1607+
1608+
Inherit<Special> specialized_explicit;
1609+
(void)specialized_explicit;
1610+
// expected-warning@#TYPE_INHERIT_WITH_EXPLICIT {{field in 'Inherit<Special>' is not explicitly initialized, but was marked as requiring explicit initialization}} expected-note@#FIELD_G3 {{'g3' declared here}}
1611+
1612+
InheritWithExplicit<Special> specialized_implicit; // no-warning
1613+
(void)specialized_implicit;
15761614
}

0 commit comments

Comments
 (0)