From 75c5639de1dba21290c3a88c440963c3c14fa827 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 11 Feb 2019 21:00:16 +0100 Subject: [PATCH] re PR c++/88977 (__builtin_is_constant_evaluated() as function template argument causes substitution failure) PR c++/88977 * pt.c (convert_nontype_argument): Pass true as manifestly_const_eval to maybe_constant_value calls. * g++.dg/cpp2a/is-constant-evaluated7.C: New test. From-SVN: r268780 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 6 ++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated7.C | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 885cd50..3bfd06f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-02-11 Jakub Jelinek + + PR c++/88977 + * pt.c (convert_nontype_argument): Pass true as manifestly_const_eval + to maybe_constant_value calls. + 2019-02-11 Marek Polacek * typeck2.c (digest_init_r): Remove commented code. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b8fbf40..eb17976 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6821,12 +6821,14 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) /* Make sure we return NULL_TREE only if we have really issued an error, as described above. */ return (complain & tf_error) ? NULL_TREE : error_mark_node; - expr = maybe_constant_value (expr); + expr = maybe_constant_value (expr, NULL_TREE, + /*manifestly_const_eval=*/true); expr = convert_from_reference (expr); } else if (TYPE_PTR_OR_PTRMEM_P (type)) { - tree folded = maybe_constant_value (expr); + tree folded = maybe_constant_value (expr, NULL_TREE, + /*manifestly_const_eval=*/true); if (TYPE_PTR_P (type) ? integer_zerop (folded) : null_member_pointer_value_p (folded)) expr = folded; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 032d078..afcf630 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-02-11 Jakub Jelinek + + PR c++/88977 + * g++.dg/cpp2a/is-constant-evaluated7.C: New test. + 2019-02-12 Wilco Dijkstra PR tree-optimization/86637 diff --git a/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated7.C b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated7.C new file mode 100644 index 0000000..72082f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated7.C @@ -0,0 +1,18 @@ +// P0595R2 +// PR c++/88977 +// { dg-do compile { target c++11 } } + +namespace std { + constexpr inline bool + is_constant_evaluated () noexcept + { + return __builtin_is_constant_evaluated (); + } +} + +template constexpr bool foo () { return B; } + +constexpr bool x = foo (); +constexpr bool y = foo<__builtin_is_constant_evaluated ()> (); +static_assert (x, ""); +static_assert (y, ""); -- 2.7.4