r336233 - [Sema] Discarded statment should be an evaluatable context.

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 3 15:15:36 PDT 2018


Author: epilk
Date: Tue Jul  3 15:15:36 2018
New Revision: 336233

URL: http://llvm.org/viewvc/llvm-project?rev=336233&view=rev
Log:
[Sema] Discarded statment should be an evaluatable context.

The constexpr evaluator was erroring out because these templates weren't
defined. Despite being used in a discarded statement, we still need to constexpr
evaluate them, which means that we need to instantiate them. Fixes PR37585.

Differential revision: https://reviews.llvm.org/D48322

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx1z.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=336233&r1=336232&r2=336233&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jul  3 15:15:36 2018
@@ -14237,13 +14237,13 @@ static bool isEvaluatableContext(Sema &S
   switch (SemaRef.ExprEvalContexts.back().Context) {
     case Sema::ExpressionEvaluationContext::Unevaluated:
     case Sema::ExpressionEvaluationContext::UnevaluatedAbstract:
-    case Sema::ExpressionEvaluationContext::DiscardedStatement:
       // Expressions in this context are never evaluated.
       return false;
 
     case Sema::ExpressionEvaluationContext::UnevaluatedList:
     case Sema::ExpressionEvaluationContext::ConstantEvaluated:
     case Sema::ExpressionEvaluationContext::PotentiallyEvaluated:
+    case Sema::ExpressionEvaluationContext::DiscardedStatement:
       // Expressions in this context could be evaluated.
       return true;
 

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1z.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx1z.cpp?rev=336233&r1=336232&r2=336233&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx1z.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx1z.cpp Tue Jul  3 15:15:36 2018
@@ -46,3 +46,16 @@ namespace Cxx17CD_NB_GB19 {
   const int &r = 0;
   constexpr int n = r;
 }
+
+namespace PR37585 {
+template <class T> struct S { static constexpr bool value = true; };
+template <class T> constexpr bool f() { return true; }
+template <class T> constexpr bool v = true;
+
+void test() {
+  if constexpr (true) {}
+  else if constexpr (f<int>()) {}
+  else if constexpr (S<int>::value) {}
+  else if constexpr (v<int>) {}
+}
+}




More information about the cfe-commits mailing list