[PATCH] D48322: [Sema] Discarded statment should be an evaluatable context
Erik Pilkington via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 19 06:53:37 PDT 2018
erik.pilkington created this revision.
erik.pilkington added a reviewer: rsmith.
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 https://llvm.org/PR37585
Thanks!
Repository:
rC Clang
https://reviews.llvm.org/D48322
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/constant-expression-cxx1z.cpp
Index: clang/test/SemaCXX/constant-expression-cxx1z.cpp
===================================================================
--- clang/test/SemaCXX/constant-expression-cxx1z.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1z.cpp
@@ -46,3 +46,16 @@
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>) {}
+}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14143,13 +14143,13 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48322.151910.patch
Type: text/x-patch
Size: 1504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180619/e62165cd/attachment.bin>
More information about the cfe-commits
mailing list