This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Fix ICE with statement expression (PR c++/71728)


OK.

On Thu, Jul 21, 2016 at 12:09 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> It is true that parsing should make sure that GOTO_EXPRs (other than
> break/continue) aren't allowed in constant expression contexts, but
> potential_constant_expression_1 may be called (with tf_none) also
> on arbitrary code either for warning purposes, or (very recent change)
> also in cp_fully_fold, usually from maybe_constant_value.
>
> So asserting they don't appear doesn't work.
>
> Fixed thusly, alternatively we could assert that (flags & tf_error) == 0
> before returning false.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/6.2?
>
> 2016-07-21  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/71728
>         * constexpr.c (potential_constant_expression_1) <case GOTO_EXPR>:
>         Replace assert with test, return false if the goto isn't break
>         or continue.  Formatting fix.
>
>         * g++.dg/other/pr71728.C: New test.
>
> --- gcc/cp/constexpr.c.jj       2016-07-21 08:59:50.000000000 +0200
> +++ gcc/cp/constexpr.c  2016-07-21 12:05:16.828618186 +0200
> @@ -5289,10 +5289,12 @@ potential_constant_expression_1 (tree t,
>      case GOTO_EXPR:
>        {
>         tree *target = &TREE_OPERAND (t, 0);
> -       /* Gotos representing break and continue are OK; we should have
> -          rejected other gotos in parsing.  */
> -       gcc_assert (breaks (target) || continues (target));
> -       return true;
> +       /* Gotos representing break and continue are OK.  */
> +       if (breaks (target) || continues (target))
> +         return true;
> +       if (flags & tf_error)
> +         error ("%<goto%> is not a constant-expression");
> +       return false;
>        }
>
>      default:
> @@ -5300,7 +5302,7 @@ potential_constant_expression_1 (tree t,
>         return false;
>
>        sorry ("unexpected AST of kind %s", get_tree_code_name (TREE_CODE (t)));
> -      gcc_unreachable();
> +      gcc_unreachable ();
>        return false;
>      }
>  #undef RECUR
> --- gcc/testsuite/g++.dg/other/pr71728.C.jj     2016-07-21 12:13:31.686461551 +0200
> +++ gcc/testsuite/g++.dg/other/pr71728.C        2016-07-21 12:14:46.974524876 +0200
> @@ -0,0 +1,11 @@
> +// PR c++/71728
> +// { dg-do compile }
> +// { dg-options "-std=gnu++14 -Wall" }
> +
> +int
> +foo ()
> +{
> +  if (({ goto test; test: 1; }) != 1)
> +    return 1;
> +  return 2;
> +}
>
>         Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]