public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/97975] [8/9/10 Regression] ICE unexpected expression '(int)A< <template-parameter-1-1> >::b' of kind implicit_conv_expr
Date: Tue, 05 Jan 2021 21:31:52 +0000	[thread overview]
Message-ID: <bug-97975-4-SnKo7enikS@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97975-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97975

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:d0684e49ee8d859fc527b22aaaaed206930371a3

commit r10-9207-gd0684e49ee8d859fc527b22aaaaed206930371a3
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Dec 1 10:39:08 2020 -0500

    c++: Fix ICE with inline variable in template [PR97975]

    In this test, we have

      static inline const int c = b;

    in a class template, and we call store_init_value as usual.  There, the
    value is

      IMPLICIT_CONV_EXPR<const float>(b)

    which is is_nondependent_static_init_expression but isn't
    is_nondependent_constant_expression (they only differ in STRICT).
    We call fold_non_dependent_expr, but that just returns the expression
    because it only instantiates is_nondependent_constant_expression
    expressions.  Since we're not checking the initializer of a constexpr
    variable, we go on to call maybe_constant_init, whereupon we crash
    because it tries to evaluate all is_nondependent_static_init_expression
    expressions, which our value is, but it still contains a template code.

    I think the fix is to call fold_non_dependent_init instead of
    maybe_constant_init, and only call fold_non_dependent_expr on the
    "this is a constexpr variable" path so as to avoid instantiating twice
    in a row.  Outside a template this should also avoid evaluating the
    value twice.

    gcc/cp/ChangeLog:

            PR c++/97975
            * constexpr.c (fold_non_dependent_init): Add a tree parameter.
            Use it.
            * cp-tree.h (fold_non_dependent_init): Add a tree parameter with
            a default value.
            * typeck2.c (store_init_value): Call fold_non_dependent_expr
            only when checking the initializer for constexpr variables.
            Call fold_non_dependent_init instead of maybe_constant_init.

    gcc/testsuite/ChangeLog:

            PR c++/97975
            * g++.dg/cpp1z/inline-var8.C: New test.

    (cherry picked from commit 69bf1c7d5ee21392334f1982d1b40c38e103bbd4)

  parent reply	other threads:[~2021-01-05 21:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 18:34 [Bug c++/97975] New: " gscfq@t-online.de
2020-11-25  8:12 ` [Bug c++/97975] " marxin at gcc dot gnu.org
2020-12-01  2:58 ` [Bug c++/97975] [8/9/10/11 Regression] " mpolacek at gcc dot gnu.org
2020-12-01  2:58 ` mpolacek at gcc dot gnu.org
2020-12-02 19:39 ` cvs-commit at gcc dot gnu.org
2020-12-02 19:40 ` [Bug c++/97975] [8/9/10 " mpolacek at gcc dot gnu.org
2021-01-05 21:31 ` cvs-commit at gcc dot gnu.org [this message]
2021-01-05 21:36 ` [Bug c++/97975] [8/9 " mpolacek at gcc dot gnu.org
2024-03-26 17:19 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97975-4-SnKo7enikS@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).