public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Marek Polacek <mpolacek@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7548] c++: Wrong error with alias template in class tmpl [PR104108] Date: Tue, 8 Mar 2022 22:50:38 +0000 (GMT) [thread overview] Message-ID: <20220308225038.194653858C83@sourceware.org> (raw) https://gcc.gnu.org/g:d54ce4641ed106666208be36fd514cae8ff1153c commit r12-7548-gd54ce4641ed106666208be36fd514cae8ff1153c Author: Marek Polacek <polacek@redhat.com> Date: Tue Mar 8 13:55:15 2022 -0500 c++: Wrong error with alias template in class tmpl [PR104108] In r10-6329 I tried to optimize the number of calls to v_d_e_p in convert_nontype_argument by remembering whether the expression was value-dependent in a bool flag. I did that wrongly assuming that its value-dependence will not be changed by build_converted_constant_expr. This testcase shows that it can: b_c_c_e gets a VAR_DECL for m_parameter, which is not value-dependent, but we're converting it to "const int &" so it returns (const int &)(const int *) &m_parameter which suddenly becomes value-dependent because of the added ADDR_EXPR: has_value_dependent_address is now true because m_parameter's context S<T> is dependent. With this bug in place, we went to the second branch here: if (TYPE_REF_OBJ_P (TREE_TYPE (expr)) && val_dep_p) /* OK, dependent reference. We don't want to ask whether a DECL is itself value-dependent, since what we want here is its address. */; else { expr = build_address (expr); if (invalid_tparm_referent_p (type, expr, complain)) return NULL_TREE; } wherein build_address created a bad tree and then i_t_r_p complained. PR c++/104108 gcc/cp/ChangeLog: * pt.cc (convert_nontype_argument): Recompute value_dependent_expression_p after build_converted_constant_expr. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/alias-decl-74.C: New test. Diff: --- gcc/cp/pt.cc | 4 +++- gcc/testsuite/g++.dg/cpp0x/alias-decl-74.C | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index c350ebb0a79..d47483dd4f2 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -7316,7 +7316,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) if (non_dep) expr = instantiate_non_dependent_expr_internal (expr, complain); - const bool val_dep_p = value_dependent_expression_p (expr); + bool val_dep_p = value_dependent_expression_p (expr); if (val_dep_p) expr = canonicalize_expr_argument (expr, complain); else @@ -7357,6 +7357,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) expr = maybe_constant_value (expr, NULL_TREE, /*manifestly_const_eval=*/true); expr = convert_from_reference (expr); + /* EXPR may have become value-dependent. */ + val_dep_p = value_dependent_expression_p (expr); } else if (TYPE_PTR_OR_PTRMEM_P (type)) { diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-74.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-74.C new file mode 100644 index 00000000000..8382d856382 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-74.C @@ -0,0 +1,9 @@ +// PR c++/104108 +// { dg-do compile { target c++11 } } + +template<template<const int&> class T> +struct S { + static int m_parameter; + template<template<const int&> class TT> + using U = TT<m_parameter>; +};
reply other threads:[~2022-03-08 22:50 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220308225038.194653858C83@sourceware.org \ --to=mpolacek@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).