public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "davveston at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98820] New: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments Date: Mon, 25 Jan 2021 11:02:31 +0000 [thread overview] Message-ID: <bug-98820-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98820 Bug ID: 98820 Summary: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: davveston at gmail dot com Target Milestone: --- As per [temp.param]/6 in N4861, for non-template parameters (including a type that contains a placeholder type): "[...] The top-level cv-qualifiers on the template-parameter are ignored when determining its type." and as per [dcl.type.decltype]/1.2: "For an expression E, the type denoted by decltype(E) is defined as follows: - [...] naming a non-type template-parameter, decltype(E) is the type of the template-parameter after performing any necessary type deduction [...]" Thus, the following example should arguably be well-formed: #include <type_traits> struct A{}; template <auto a> void f() { static_assert(std::is_same_v<decltype(a), A>); } template <auto const a> void g() { static_assert(std::is_same_v<decltype(a), A>); } int main() { constexpr A a{}; f<a>(); g<a>(); } However GCC rejects it as `decltype(a)` resolves to `A const` rather than `A`. --- We may note that: 1) Clang accepts the program, and 2) Both Clang and GCC accepts the program when using a structural type directly instead of a placeholder type for the non-type template parameter; replacing the definitions of `f` and `g` above with: template <A a> void f() { static_assert(std::is_same_v<decltype(a), A>); } template <A const a> void g() { static_assert(std::is_same_v<decltype(a), A>); } 3) Both clang and GCC accepts the program when using a placeholder type but with a non-class type as template argument to it; replacing the definitions of `f` and `g` above with: template <auto a> void f() { static_assert(std::is_same_v<decltype(a), int>); } template <auto const a> void g() { static_assert(std::is_same_v<decltype(a), int>); } and calling them as f<0>() and g<0>(); --- These standard rules are arguably somewhat confusing given that the template parameter object itself (associated with the class-type non-type template parameter) is `const` ([temp.param]/8).
next reply other threads:[~2021-01-25 11:02 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-25 11:02 davveston at gmail dot com [this message] 2021-02-12 4:55 ` [Bug c++/98820] " mpolacek at gcc dot gnu.org 2023-09-15 17:38 ` ppalka at gcc dot gnu.org 2023-09-15 17:41 ` ppalka 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-98820-4@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: 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).