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-1310] c++: explicit() ignored on deduction guide [PR100065] Date: Tue, 8 Jun 2021 22:29:59 +0000 (GMT) [thread overview] Message-ID: <20210608222959.8A736385DC33@sourceware.org> (raw) https://gcc.gnu.org/g:1afa4facb9348cac0349ff9c30066aa25a3608f7 commit r12-1310-g1afa4facb9348cac0349ff9c30066aa25a3608f7 Author: Marek Polacek <polacek@redhat.com> Date: Mon Jun 7 16:06:00 2021 -0400 c++: explicit() ignored on deduction guide [PR100065] When we have explicit() with a value-dependent argument, we can't evaluate it at parsing time, so cp_parser_function_specifier_opt stashes the argument into the decl-specifiers and grokdeclarator then stores it into explicit_specifier_map, which is then used when substituting the function decl. grokdeclarator stores it for constructors and conversion functions, but we also need to do it for deduction guides, otherwise we'll forget that we've seen an explicit-specifier as in the attached test. PR c++/100065 gcc/cp/ChangeLog: * decl.c (grokdeclarator): Store a value-dependent explicit-specifier even for deduction guides. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/explicit18.C: New test. Diff: --- gcc/cp/decl.c | 2 ++ gcc/testsuite/g++.dg/cpp2a/explicit18.C | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a3687dbb0dd..cbf647dd569 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14043,6 +14043,8 @@ grokdeclarator (const cp_declarator *declarator, storage_class = sc_none; } } + if (declspecs->explicit_specifier) + store_explicit_specifier (decl, declspecs->explicit_specifier); } else { diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit18.C b/gcc/testsuite/g++.dg/cpp2a/explicit18.C new file mode 100644 index 00000000000..c8916fa4743 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/explicit18.C @@ -0,0 +1,23 @@ +// PR c++/100065 +// { dg-do compile { target c++20 } } + +template<bool B> +struct bool_constant { + static constexpr bool value = B; + constexpr operator bool() const { return value; } +}; + +using true_type = bool_constant<true>; +using false_type = bool_constant<false>; + +template<bool> +struct X { + template<typename T> + X(T); +}; + +template<bool b> +explicit(b) X(bool_constant<b>) -> X<b>; + +X false_ = false_type{}; // OK +X true_ = true_type{}; // { dg-error "explicit deduction guide" }
reply other threads:[~2021-06-08 22:29 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=20210608222959.8A736385DC33@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).