Skip to content

Commit 02a33b7

Browse files
authored
"Reapply "[Sema] Fix crash on invalid code with parenthesized aggrega… (#76833)
…te initialization" (#76272)"" With updates the libc++ tests. This reverts commit 2205d23 and relands 86dc6e1 and 7ab16fb. Original commit was reverted because of failing libc++ tests, see #76232 for the discussion. The errors in the tests are spurious in the first place (coming from initialization of invalid classes), so update the tests to match new behavior that does not show those errors. The original patch was written by @ilya-biryukov To fix the CI two libc++ tests are temporary disabled for clang-18.
1 parent 848d7af commit 02a33b7

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5512,6 +5512,14 @@ static void TryOrBuildParenListInitialization(
55125512
} else if (auto *RT = Entity.getType()->getAs<RecordType>()) {
55135513
bool IsUnion = RT->isUnionType();
55145514
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
5515+
if (RD->isInvalidDecl()) {
5516+
// Exit early to avoid confusion when processing members.
5517+
// We do the same for braced list initialization in
5518+
// `CheckStructUnionTypes`.
5519+
Sequence.SetFailed(
5520+
clang::InitializationSequence::FK_ParenthesizedListInitFailed);
5521+
return;
5522+
}
55155523

55165524
if (!IsUnion) {
55175525
for (const CXXBaseSpecifier &Base : RD->bases()) {

clang/test/SemaCXX/crash-GH76228.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -std=c++20 -verify %s
2+
// Check we don't crash on incomplete members and bases when handling parenthesized initialization.
3+
class incomplete; // expected-note@-0 3 {{forward declaration of 'incomplete'}}
4+
struct foo {
5+
int a;
6+
incomplete b;
7+
// expected-error@-1 {{incomplete type}}
8+
};
9+
foo a1(0);
10+
11+
struct one_int {
12+
int a;
13+
};
14+
struct bar : one_int, incomplete {};
15+
// expected-error@-1 {{incomplete type}}
16+
bar a2(0);
17+
18+
incomplete a3[3](1,2,3);
19+
// expected-error@-1 {{incomplete type}}
20+
21+
struct qux : foo {
22+
};
23+
qux a4(0);
24+
25+
struct fred {
26+
foo a[3];
27+
};
28+
fred a5(0);

clang/test/SemaCXX/paren-list-agg-init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ int test() {
289289
// used to crash
290290
S a(0, 1);
291291
S b(0);
292-
S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' from a parenthesized list of values is a C++20 extension}}
292+
S c(0, 0, 1);
293293

294294
S d {0, 1};
295295
S e {0};

libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// https://github.com/llvm/llvm-project/pull/76232 breaks this libc++ test.
10+
// The fix would be to update this file. The issue is that the CI uses 2
11+
// versions of Clang-18
12+
// - An older nightly build as the main compiler
13+
// - A freshly bootstrap build
14+
// This means the test can't be used until the nightly build is updated.
15+
// TODO(mordante) Reenable clang-18.
16+
// UNSUPPORTED: clang-18
17+
918
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1019

1120
// Test the mandates

libcxx/test/libcxx/utilities/expected/expected.void/transform_error.mandates.verify.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
// https://github.com/llvm/llvm-project/pull/76232 breaks this libc++ test.
10+
// The fix would be to update this file. The issue is that the CI uses 2
11+
// versions of Clang-18
12+
// - An older nightly build as the main compiler
13+
// - A freshly bootstrap build
14+
// This means the test can't be used until the nightly build is updated.
15+
// TODO(mordante) Reenable clang-18.
16+
// UNSUPPORTED: clang-18
17+
918
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1019

1120
// Test the mandates

0 commit comments

Comments
 (0)