[PATCH] D138947: [Clang] Remove invalid assert from Sema::BuildCXXTypeConstructExpr

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 29 13:35:02 PST 2022


shafik created this revision.
shafik added reviewers: aaron.ballman, erichkeane, davide, rsmith.
Herald added a project: All.
shafik requested review of this revision.

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


https://reviews.llvm.org/D138947

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx0x-initializer-references.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1018,3 +1018,14 @@
   (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{};
+}
+}
Index: clang/test/SemaCXX/cxx0x-initializer-references.cpp
===================================================================
--- clang/test/SemaCXX/cxx0x-initializer-references.cpp
+++ clang/test/SemaCXX/cxx0x-initializer-references.cpp
@@ -140,3 +140,21 @@
 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>();
+}
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1459,9 +1459,6 @@
   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.");
   SourceRange FullRange = SourceRange(TyBeginLoc, RParenOrBraceLoc);
 
   InitializedEntity Entity =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138947.478699.patch
Type: text/x-patch
Size: 1593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221129/8d605bbf/attachment.bin>


More information about the cfe-commits mailing list