From 9dc20710e8380bdaf03551b45a2234c6d18c6519 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 16 Feb 2018 11:44:17 -0500 Subject: [PATCH] PR c++/84421 - type-dependent if constexpr * semantics.c (finish_if_stmt_cond): Check type_dependent_expression_p. From-SVN: r257744 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/semantics.c | 1 + gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C | 14 ++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ee08e689b4e..17af63328ed 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-02-16 Jason Merrill + + PR c++/84421 - type-dependent if constexpr + * semantics.c (finish_if_stmt_cond): Check type_dependent_expression_p. + 2018-02-16 Nathan Sidwell Deprecate -ffriend-injection. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index f0cee68e46f..35569d0cb0d 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -731,6 +731,7 @@ finish_if_stmt_cond (tree cond, tree if_stmt) { cond = maybe_convert_cond (cond); if (IF_STMT_CONSTEXPR_P (if_stmt) + && !type_dependent_expression_p (cond) && require_constant_expression (cond) && !value_dependent_expression_p (cond)) { diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C new file mode 100644 index 00000000000..f6cc39a0c2f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if14.C @@ -0,0 +1,14 @@ +// PR c++/84421 +// { dg-options -std=c++17 } + +struct A{ + constexpr operator bool() const { return true; } +}; + +int main(){ + auto f = [](auto v){ + if constexpr(v){} + }; + A a; + f(a); +} -- 2.30.2