[PATCH] D91162: Give up on evaluating value-dependent potential constexpr before hitting the assertion.

Adam Czachorowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 17 09:06:31 PST 2020


adamcz updated this revision to Diff 305818.
adamcz added a comment.

Added [clang] in commit description


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91162

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constexpr-value-dependent.cpp


Index: clang/test/SemaCXX/constexpr-value-dependent.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/constexpr-value-dependent.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify
+
+template<int x> constexpr int f(int y) {
+  return x * y;
+}
+
+// The error makes the CallExpr become potentially value-dependent. This used to
+// cause a crash.
+constexpr int test(int x) {
+  return f<1>(f<x>(1)); // expected-error {{no matching function for call to 'f'}} expected-note at -7{{candidate template ignored}}
+}
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5981,6 +5981,9 @@
 static bool EvaluateCallArg(const ParmVarDecl *PVD, const Expr *Arg,
                             CallRef Call, EvalInfo &Info,
                             bool NonNull = false) {
+  if (Arg->isValueDependent())
+    return false;
+
   LValue LV;
   // Create the parameter slot and register its destruction. For a vararg
   // argument, create a temporary.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91162.305818.patch
Type: text/x-patch
Size: 1152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201117/b66e11ec/attachment-0001.bin>


More information about the cfe-commits mailing list