[clang] ef10f81 - [Clang] Adjust assert from Sema::BuildCXXTypeConstructExpr
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 1 09:40:28 PST 2022
Author: Shafik Yaghmour
Date: 2022-12-01T09:40:18-08:00
New Revision: ef10f81985f665c553c818e1c5962aebb8f36f0c
URL: https://github.com/llvm/llvm-project/commit/ef10f81985f665c553c818e1c5962aebb8f36f0c
DIFF: https://github.com/llvm/llvm-project/commit/ef10f81985f665c553c818e1c5962aebb8f36f0c.diff
LOG: [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:
https://github.com/llvm/llvm-project/issues/58302
https://github.com/llvm/llvm-project/issues/58753
https://github.com/llvm/llvm-project/issues/59100
Differential Revision: https://reviews.llvm.org/D138947
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/cxx0x-initializer-references.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7580b14fac5d6..ff97240e1322b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -311,6 +311,11 @@ Bug Fixes
`Issue 58067 <https://github.com/llvm/llvm-project/issues/58057>`_
`Issue 59014 <https://github.com/llvm/llvm-project/issues/59014>`_
`Issue 54746 <https://github.com/llvm/llvm-project/issues/54746>`_
+- Fix assert that triggers a crash during some types of list initialization that
+ generate a CXXTemporaryObjectExpr instead of a InitListExpr. This fixes
+ `Issue 58302 <https://github.com/llvm/llvm-project/issues/58302>`_
+ `Issue 58753 <https://github.com/llvm/llvm-project/issues/58753>`_
+ `Issue 59100 <https://github.com/llvm/llvm-project/issues/59100>`_
Improvements to Clang's diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 141250f1b311a..27ce8b4d93638 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1459,9 +1459,8 @@ Sema::BuildCXXTypeConstructExpr(TypeSourceInfo *TInfo,
QualType Ty = TInfo->getType();
SourceLocation TyBeginLoc = TInfo->getTypeLoc().getBeginLoc();
- assert((!ListInitialization ||
- (Exprs.size() == 1 && isa<InitListExpr>(Exprs[0]))) &&
- "List initialization must have initializer list as expression.");
+ assert((!ListInitialization || Exprs.size() == 1) &&
+ "List initialization must have exactly one expression.");
SourceRange FullRange = SourceRange(TyBeginLoc, RParenOrBraceLoc);
InitializedEntity Entity =
diff --git a/clang/test/SemaCXX/cxx0x-initializer-references.cpp b/clang/test/SemaCXX/cxx0x-initializer-references.cpp
index e2510bc039e5d..0f816a39f2ba0 100644
--- a/clang/test/SemaCXX/cxx0x-initializer-references.cpp
+++ b/clang/test/SemaCXX/cxx0x-initializer-references.cpp
@@ -140,3 +140,21 @@ namespace PR20844 {
namespace PR21834 {
const int &a = (const int &){0}; // expected-error {{cannot bind to an initializer list}}
}
+
+namespace GH59100 {
+class v {};
+
+template <typename T>
+class V : public v {};
+
+using T = const V<int> &;
+
+template <class D>
+void f() {
+ auto t = T{};
+}
+
+void z() {
+ f<int>();
+}
+}
diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp b/clang/test/SemaCXX/cxx2a-consteval.cpp
index 1a8097797bc3c..6ae2664046d71 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1018,3 +1018,14 @@ void g() {
(void)[](int i) consteval { return i; }(0);
}
} // namespace GH50455
+
+namespace GH58302 {
+struct A {
+ consteval A(){}
+ consteval operator int() { return 1;}
+};
+
+int f() {
+ int x = A{};
+}
+}
More information about the cfe-commits
mailing list