Skip to content

Commit 4182c29

Browse files
committed
[clang] Avoid doing C++20 aggregate init during copy-initialization
1 parent a54f75b commit 4182c29

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6714,7 +6714,8 @@ void InitializationSequence::InitializeFrom(Sema &S,
67146714
OverloadCandidateSet::iterator Best;
67156715
OverloadingResult OR = getFailedCandidateSet().BestViableFunction(
67166716
S, Kind.getLocation(), Best);
6717-
if (OR != OverloadingResult::OR_Deleted) {
6717+
if (OR != OverloadingResult::OR_Deleted &&
6718+
Kind.getKind() == InitializationKind::IK_Direct) {
67186719
// C++20 [dcl.init] 17.6.2.2:
67196720
// - Otherwise, if no constructor is viable, the destination type is
67206721
// an
Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
22

3-
// If the initializer is (), the object is value-initialized.
4-
5-
// expected-no-diagnostics
63
namespace GH69890 {
7-
struct A {
8-
constexpr A() {}
9-
int x;
10-
};
4+
// If the initializer is (), the object is value-initialized.
5+
struct A {
6+
constexpr A() {}
7+
int x;
8+
};
9+
10+
struct B : A {
11+
int y;
12+
};
13+
14+
static_assert(B().x == 0);
15+
static_assert(B().y == 0);
16+
} // namespace GH69890
17+
18+
namespace P0960R3 {
19+
struct A { // expected-note 9 {{candidate constructor}}
20+
int i;
21+
operator int() volatile;
22+
};
23+
24+
volatile A va;
25+
A a = va; // expected-error {{no matching constructor for initialization of 'A'}}
1126

12-
struct B : A {
13-
int y;
14-
};
27+
A f() {
28+
return va; // expected-error {{no matching constructor for initialization of 'A'}}
29+
}
1530

16-
static_assert(B().x == 0);
17-
static_assert(B().y == 0);
18-
}
31+
int g(A); // expected-note {{passing argument to parameter here}}
32+
int g(auto&&);
33+
int i = g(va); // expected-error {{no matching constructor for initialization of 'A'}}
34+
} // namespace P0960R3

0 commit comments

Comments
 (0)