[PATCH] D145892: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag

Congcong Cai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 14 09:05:48 PDT 2023


HerrCai0907 updated this revision to Diff 505134.
HerrCai0907 added a comment.

rebase to main


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145892/new/

https://reviews.llvm.org/D145892

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/SemaCXX/fold_expr_typo.cpp


Index: clang/test/SemaCXX/fold_expr_typo.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template <typename... T>
+void foo(T &&...Params) {
+  foo<T>(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+                      expected-error {{use of undeclared identifier 'Unknown'}}
+  ((foo<T>(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template <typename... U> struct A {
+  template <typename... T> void foo(T &&...Params) {
+    foo<T>((... + static_cast<U>(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+  }
+};
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@
   if (!LHS || !RHS) {
     Expr *Pack = LHS ? LHS : RHS;
     assert(Pack && "fold expression with neither LHS nor RHS");
-    DiscardOperands();
-    if (!Pack->containsUnexpandedParameterPack())
+    if (!Pack->containsUnexpandedParameterPack()) {
+      DiscardOperands();
       return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
              << Pack->getSourceRange();
+    }
   }
 
   BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -197,6 +197,8 @@
   be reached despite being reachable. This fixes
   `#61177 <https://github.com/llvm/llvm-project/issues/61177>`_ in anticipation
   of `CWG2699 <https://wg21.link/CWG2699>_` being accepted by WG21.
+- Fix crash when parsing fold expression containing a delayed typo correction.
+  (`#61326 <https://github.com/llvm/llvm-project/issues/61326>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145892.505134.patch
Type: text/x-patch
Size: 2089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230314/6013f7f1/attachment.bin>


More information about the cfe-commits mailing list