From: Marek Polacek Date: Thu, 22 Mar 2018 08:08:07 +0000 (+0000) Subject: re PR c++/84854 (ICE: unexpected expression in cxx_eval_constant_expression, at cp... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=08ad2797c60b66f8a6ca54652cdead0aa6ea721f;p=gcc.git re PR c++/84854 (ICE: unexpected expression in cxx_eval_constant_expression, at cp/constexpr.c:4774) PR c++/84854 * semantics.c (finish_if_stmt_cond): Check if the type of the condition is boolean. * g++.dg/cpp1z/constexpr-if15.C: New test. * g++.dg/cpp1z/constexpr-if16.C: New test. From-SVN: r258756 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 44de2fb5b37..f9e7a57ec03 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-03-22 Marek Polacek + + PR c++/84854 + * semantics.c (finish_if_stmt_cond): Check if the type of the condition + is boolean. + 2018-03-21 Jason Merrill PR c++/81311 - wrong C++17 overload resolution. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 4b9fc277436..97fa57ae94e 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -733,7 +733,10 @@ finish_if_stmt_cond (tree cond, tree if_stmt) if (IF_STMT_CONSTEXPR_P (if_stmt) && !type_dependent_expression_p (cond) && require_constant_expression (cond) - && !value_dependent_expression_p (cond)) + && !value_dependent_expression_p (cond) + /* Wait until instantiation time, since only then COND has been + converted to bool. */ + && TREE_TYPE (cond) == boolean_type_node) { cond = instantiate_non_dependent_expr (cond); cond = cxx_constant_value (cond, NULL_TREE); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cc4cbbc857f..00b804c7018 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-03-22 Marek Polacek + + PR c++/84854 + * g++.dg/cpp1z/constexpr-if15.C: New test. + * g++.dg/cpp1z/constexpr-if16.C: New test. + 2018-03-21 Joseph Myers * gcc.dg/builtin-tgmath-3.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C new file mode 100644 index 00000000000..9a9053c3305 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if15.C @@ -0,0 +1,11 @@ +// PR c++/84854 +// { dg-options -std=c++17 } + +constexpr int foo () { return 1; } +constexpr int foo (int) { return 2; } + +template +void a() +{ + if constexpr(foo) { }; +} diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if16.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if16.C new file mode 100644 index 00000000000..31a149702fd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if16.C @@ -0,0 +1,20 @@ +// { dg-options -std=c++17 } + +struct A +{ + constexpr operator bool () { return true; } + int i; +}; + +A a; + +template void f() +{ + constexpr bool b = a; + if constexpr (a) { } +} + +int main() +{ + f(); +}