public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98820] New: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments
@ 2021-01-25 11:02 davveston at gmail dot com
  2021-02-12  4:55 ` [Bug c++/98820] " mpolacek at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: davveston at gmail dot com @ 2021-01-25 11:02 UTC (permalink / raw)
  To: gcc-bugs

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).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/98820] Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments
  2021-01-25 11:02 [Bug c++/98820] New: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments davveston at gmail dot com
@ 2021-02-12  4:55 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-02-12  4:55 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |mpolacek at gcc dot gnu.org
   Last reconfirmed|                            |2021-02-12
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed, I guess.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/98820] Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments
  2021-01-25 11:02 [Bug c++/98820] New: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments davveston at gmail dot com
  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
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-09-15 17:38 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johelegp at gmail dot com

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 99631 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/98820] Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments
  2021-01-25 11:02 [Bug c++/98820] New: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments davveston at gmail dot com
  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
  2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-09-15 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
dup

*** This bug has been marked as a duplicate of bug 99631 ***

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-15 17:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25 11:02 [Bug c++/98820] New: Placeholder (auto) non-type template parameter wrongly deduced to 'const' for class type arguments davveston at gmail dot com
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

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).