[PR c++/84596] implicit conv in static assert
Jason Merrill
jason@redhat.com
Thu Mar 1 16:58:00 GMT 2018
On Thu, Mar 1, 2018 at 11:28 AM, Marek Polacek <polacek@redhat.com> wrote:
> On Wed, Feb 28, 2018 at 02:01:06PM -0500, Jason Merrill wrote:
>> On Wed, Feb 28, 2018 at 8:57 AM, Marek Polacek <polacek@redhat.com> wrote:
>> > On Wed, Feb 28, 2018 at 09:11:24AM -0300, Alexandre Oliva wrote:
>> >> Evaluation of constant expressions, such as those passed to
>> >> static_assert, ICEd when encountering IMPLICIT_CONV_EXPRs.
>> >>
>> >> Handle them like CONVERT_EXPR and NOP_EXPR.
>> >>
>> >> Regstrapped on x86_64- and i686-linux-gnu. Ok to install?
>> >>
>> >> for gcc/cp/ChangeLog
>> >>
>> >> PR c++/84596
>> >> * constexpr.c (cxx_eval_constant_expression): Handle
>> >> IMPLICIT_CONV_EXPR.
>> >>
>> >> for gcc/testsuite/ChangeLog
>> >>
>> >> PR c++/84596
>> >> * g++.dg/cpp0x/pr84596.C: New.
>> >> ---
>> >> gcc/cp/constexpr.c | 1 +
>> >> gcc/testsuite/g++.dg/cpp0x/pr84596.C | 7 +++++++
>> >> 2 files changed, 8 insertions(+)
>> >> create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr84596.C
>> >>
>> >> diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
>> >> index 4bbdbf434877..d38e2d83ae8c 100644
>> >> --- a/gcc/cp/constexpr.c
>> >> +++ b/gcc/cp/constexpr.c
>> >> @@ -4549,6 +4549,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
>> >> non_constant_p, overflow_p);
>> >> break;
>> >>
>> >> + case IMPLICIT_CONV_EXPR:
>> >> case CONVERT_EXPR:
>> >> case VIEW_CONVERT_EXPR:
>> >> case NOP_EXPR:
>> >
>> > I don't think it's correct to handle template codes here; they shouldn't
>> > have gotten to cxx_eval_constant_expression in the first place. Usually
>> > they're substituted in instantiate_non_dependent_expr_internal e.g. via
>> > calling fold_non_dependent_expr. So I guess we need to find out how
>> > IMPLICIT_CONV_EXPR has gotten there.
>>
>> Agreed.
>
> Here's my take on this; Alex, sorry for interfering.
>
> The problem is that perform_implicit_conversion_flags in finish_static_assert
> produces "implicit_conv_expr <c>" where "c" is a PARM_DECL. Subsequent
> fold_non_dependent_expr is supposed to substitute that implicit_conv_expr but
> doesn't because the expression is not is_nondependent_constant_expression --
> a PARM_DECL is only considered a potentially constant expression if NOW is
> false, which it isn't. But the require_potential_rvalue_constant_expression
> call that follows uses NOW = false. So I think we need the following.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2018-03-01 Marek Polacek <polacek@redhat.com>
>
> PR c++/84596
> * constexpr.c (require_rvalue_constant_expression): New function.
> * cp-tree.h: Declare it.
> * semantics.c (finish_static_assert): Use it instead of
> require_potential_rvalue_constant_expression.
>
> * g++.dg/cpp0x/static_assert14.C: New test.
OK.
Jason
More information about the Gcc-patches
mailing list