Skip to content

Commit ef10f81

Browse files
committed
[Clang] Adjust assert from Sema::BuildCXXTypeConstructExpr
Currently Sema::BuildCXXTypeConstructExpr asserts that list initialization must mean we have an InitListExpr as well. We have several cases of valid code the result in CXXTemporaryObjectExpr in the AST instead for list initialization. Commit 1ae689c seems to indicate that this is not unexpected, although may be a design issue This fixes: llvm#58302 llvm#58753 llvm#59100 Differential Revision: https://reviews.llvm.org/D138947
1 parent f4eb87f commit ef10f81

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ Bug Fixes
311311
`Issue 58067 <https://github.com/llvm/llvm-project/issues/58057>`_
312312
`Issue 59014 <https://github.com/llvm/llvm-project/issues/59014>`_
313313
`Issue 54746 <https://github.com/llvm/llvm-project/issues/54746>`_
314+
- Fix assert that triggers a crash during some types of list initialization that
315+
generate a CXXTemporaryObjectExpr instead of a InitListExpr. This fixes
316+
`Issue 58302 <https://github.com/llvm/llvm-project/issues/58302>`_
317+
`Issue 58753 <https://github.com/llvm/llvm-project/issues/58753>`_
318+
`Issue 59100 <https://github.com/llvm/llvm-project/issues/59100>`_
314319

315320
Improvements to Clang's diagnostics
316321
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,9 +1459,8 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
14591459
QualType Ty = TInfo->getType();
14601460
SourceLocation TyBeginLoc = TInfo->getTypeLoc().getBeginLoc();
14611461

1462-
assert((!ListInitialization ||
1463-
(Exprs.size() == 1 && isa<InitListExpr>(Exprs[0]))) &&
1464-
"List initialization must have initializer list as expression.");
1462+
assert((!ListInitialization || Exprs.size() == 1) &&
1463+
"List initialization must have exactly one expression.");
14651464
SourceRange FullRange = SourceRange(TyBeginLoc, RParenOrBraceLoc);
14661465

14671466
InitializedEntity Entity =

clang/test/SemaCXX/cxx0x-initializer-references.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,21 @@ namespace PR20844 {
140140
namespace PR21834 {
141141
const int &a = (const int &){0}; // expected-error {{cannot bind to an initializer list}}
142142
}
143+
144+
namespace GH59100 {
145+
class v {};
146+
147+
template <typename T>
148+
class V : public v {};
149+
150+
using T = const V<int> &;
151+
152+
template <class D>
153+
void f() {
154+
auto t = T{};
155+
}
156+
157+
void z() {
158+
f<int>();
159+
}
160+
}

clang/test/SemaCXX/cxx2a-consteval.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,3 +1018,14 @@ void g() {
10181018
(void)[](int i) consteval { return i; }(0);
10191019
}
10201020
} // namespace GH50455
1021+
1022+
namespace GH58302 {
1023+
struct A {
1024+
consteval A(){}
1025+
consteval operator int() { return 1;}
1026+
};
1027+
1028+
int f() {
1029+
int x = A{};
1030+
}
1031+
}

0 commit comments

Comments
 (0)