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

Congcong Cai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 12 20:01:08 PDT 2023


HerrCai0907 created this revision.
HerrCai0907 added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

PR #61326
CorrectDelayedTyposInExpr will clean all typo error and should only
happen when return invalid ExprResult


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145892

Files:
  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,8 @@
+// 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'}}
+}
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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145892.504499.patch
Type: text/x-patch
Size: 1277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230313/2dc30045/attachment.bin>


More information about the cfe-commits mailing list