public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const
@ 2021-03-17 17:38 johelegp at gmail dot com
  2021-03-18 13:20 ` [Bug c++/99631] " redi at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: johelegp at gmail dot com @ 2021-03-17 17:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99631
           Summary: decltype of non-type template-parameter shouldn't be
                    const
           Product: gcc
           Version: 11.0
               URL: https://godbolt.org/z/4YY5r3
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/4YY5r3.
```C++
#include<type_traits>
template<auto V>constexpr bool is_const=std::is_const_v<decltype(V)>;
struct A{};
static_assert(!is_const<A{}>);
```
```
<source>:4:15: error: static assertion failed
    4 | static_assert(!is_const<A{}>);
      |               ^~~~~~~~~~~~~~
Compiler returned: 1
```
See https://bugs.llvm.org/show_bug.cgi?id=49609#c1 for an explanation.

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
@ 2021-03-18 13:20 ` redi at gcc dot gnu.org
  2021-03-18 13:48 ` jakub at gcc dot gnu.org
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2021-03-18 13:20 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-03-18
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I'm not sure "rejects-valid" is appropriate, as it only fails to compile
because of the static assert (i.e. you've asked for it).

But wrong-code isn't really right either, because this is before any codegen
happens. Every bug in metaprogramming results can be turned into
accepts-invalid or rejects-valid or wrong-code, but none of those keywords is
really specific to the actual form of the bug. Maybe we need a new keyword (and
no, meta-bug is it either ;-).

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
  2021-03-18 13:20 ` [Bug c++/99631] " redi at gcc dot gnu.org
@ 2021-03-18 13:48 ` jakub at gcc dot gnu.org
  2021-03-18 23:44 ` johelegp at gmail dot com
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-18 13:48 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, do we implement the http://eel.is/c++draft/dcl.type#decltype-1.2 point
anywhere?

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
  2021-03-18 13:20 ` [Bug c++/99631] " redi at gcc dot gnu.org
  2021-03-18 13:48 ` jakub at gcc dot gnu.org
@ 2021-03-18 23:44 ` johelegp at gmail dot com
  2021-11-09 17:23 ` n60wb42d2 at relay dot firefox.com
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: johelegp at gmail dot com @ 2021-03-18 23:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
Good point. How about 'conformance' for a keyword?

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (2 preceding siblings ...)
  2021-03-18 23:44 ` johelegp at gmail dot com
@ 2021-11-09 17:23 ` n60wb42d2 at relay dot firefox.com
  2022-09-26  1:46 ` johelegp at gmail dot com
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: n60wb42d2 at relay dot firefox.com @ 2021-11-09 17:23 UTC (permalink / raw)
  To: gcc-bugs

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

n60wb42d2 at relay dot firefox.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |n60wb42d2 at relay dot firefox.com

--- Comment #4 from n60wb42d2 at relay dot firefox.com ---
(In reply to Jonathan Wakely from comment #1)
> I'm not sure "rejects-valid" is appropriate, as it only fails to compile
> because of the static assert (i.e. you've asked for it).

Here it `rejects-valid`:

```c++
struct param{};

template<typename>
struct t;
template<>
struct t<param>{};

template<param... p>
auto test()
{
    (void)t<decltype(p)...>{};
}

int main()
{
    test<param{}>();
}
```
```
<source>:11:5: error: invalid use of incomplete type 'struct t<const param>'
   11 |     (void)t<decltype(p)...>{};
```

https://godbolt.org/z/MKxx1dobT

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (3 preceding siblings ...)
  2021-11-09 17:23 ` n60wb42d2 at relay dot firefox.com
@ 2022-09-26  1:46 ` johelegp at gmail dot com
  2022-09-26  1:47 ` johelegp at gmail dot com
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: johelegp at gmail dot com @ 2022-09-26  1:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
Would the existing 'wrong-code' work?

> Generates incorrect code. Has to be able to compile and link.

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (4 preceding siblings ...)
  2022-09-26  1:46 ` johelegp at gmail dot com
@ 2022-09-26  1:47 ` johelegp at gmail dot com
  2022-12-26 17:10 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: johelegp at gmail dot com @ 2022-09-26  1:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
> But wrong-code isn't really right either [...]

Oh, you already mentioned them. I suggest 'non-conforming-result', or something
more appropriate than "result" to indicate the metaprogrammingness of it.

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (5 preceding siblings ...)
  2022-09-26  1:47 ` johelegp at gmail dot com
@ 2022-12-26 17:10 ` pinskia at gcc dot gnu.org
  2023-09-15 17:38 ` ppalka at gcc dot gnu.org
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-26 17:10 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |danakj at orodu dot net

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 108169 has been marked as a duplicate of this bug. ***

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (6 preceding siblings ...)
  2022-12-26 17:10 ` pinskia at gcc dot gnu.org
@ 2023-09-15 17:38 ` ppalka at gcc dot gnu.org
  2023-09-15 17:39 ` ppalka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ 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=99631

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 #8 from Patrick Palka <ppalka at gcc dot gnu.org> ---
dup of PR98820

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

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (7 preceding siblings ...)
  2023-09-15 17:38 ` ppalka at gcc dot gnu.org
@ 2023-09-15 17:39 ` ppalka at gcc dot gnu.org
  2023-09-15 17:41 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-09-15 17:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |ASSIGNED
         Resolution|DUPLICATE                   |---
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Actually it's probably better to mark PR98820 as the dup

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (8 preceding siblings ...)
  2023-09-15 17:39 ` ppalka at gcc dot gnu.org
@ 2023-09-15 17:41 ` ppalka at gcc dot gnu.org
  2023-09-19 12:21 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ 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=99631

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

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

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

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (9 preceding siblings ...)
  2023-09-15 17:41 ` ppalka at gcc dot gnu.org
@ 2023-09-19 12:21 ` cvs-commit at gcc dot gnu.org
  2023-09-24 18:42 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-19 12:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

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

commit r14-4137-gddd064e3571c4a9e6258c75eba65585a07367712
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Sep 19 08:21:05 2023 -0400

    c++: constness of decltype of NTTP object [PR99631]

    This corrects resolving decltype of a (class) NTTP object as per
    [dcl.type.decltype]/1.2 and [temp.param]/6 in the type-dependent case.

    Note that in the non-dependent case we resolve the decltype ahead of
    time, in which case finish_decltype_type drops the const VIEW_CONVERT_EXPR
    wrapper around the TEMPLATE_PARM_INDEX, and the latter has the desired
    non-const type.

    In the type-dependent case, at instantiation time tsubst drops the
    VIEW_CONVERT_EXPR since the substituted NTTP is the already-const object
    created by get_template_parm_object.  So in this case finish_decltype_type
    sees the const object, which this patch now adds special handling for.

            PR c++/99631

    gcc/cp/ChangeLog:

            * semantics.cc (finish_decltype_type): For an NTTP object,
            return its type modulo cv-quals.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/nontype-class60.C: New test.

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (10 preceding siblings ...)
  2023-09-19 12:21 ` cvs-commit at gcc dot gnu.org
@ 2023-09-24 18:42 ` cvs-commit at gcc dot gnu.org
  2023-09-24 18:44 ` ppalka at gcc dot gnu.org
  2023-09-24 19:13 ` danakj at orodu dot net
  13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-24 18:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

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

commit r13-7835-gb9e02590f7d35f1f8e8e95ab1f2e30f24113f551
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Sep 19 08:21:05 2023 -0400

    c++: constness of decltype of NTTP object [PR99631]

    This corrects resolving decltype of a (class) NTTP object as per
    [dcl.type.decltype]/1.2 and [temp.param]/6 in the type-dependent case.

    Note that in the non-dependent case we resolve the decltype ahead of
    time, in which case finish_decltype_type drops the const VIEW_CONVERT_EXPR
    wrapper around the TEMPLATE_PARM_INDEX, and the latter has the desired
    non-const type.

    In the type-dependent case, at instantiation time tsubst drops the
    VIEW_CONVERT_EXPR since the substituted NTTP is the already-const object
    created by get_template_parm_object.  So in this case finish_decltype_type
    sees the const object, which this patch now adds special handling for.

            PR c++/99631

    gcc/cp/ChangeLog:

            * semantics.cc (finish_decltype_type): For an NTTP object,
            return its type modulo cv-quals.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/nontype-class60.C: New test.

    (cherry picked from commit ddd064e3571c4a9e6258c75eba65585a07367712)

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (11 preceding siblings ...)
  2023-09-24 18:42 ` cvs-commit at gcc dot gnu.org
@ 2023-09-24 18:44 ` ppalka at gcc dot gnu.org
  2023-09-24 19:13 ` danakj at orodu dot net
  13 siblings, 0 replies; 15+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-09-24 18:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |13.3
         Resolution|---                         |FIXED

--- Comment #13 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13.3 / 14.

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

* [Bug c++/99631] decltype of non-type template-parameter shouldn't be const
  2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
                   ` (12 preceding siblings ...)
  2023-09-24 18:44 ` ppalka at gcc dot gnu.org
@ 2023-09-24 19:13 ` danakj at orodu dot net
  13 siblings, 0 replies; 15+ messages in thread
From: danakj at orodu dot net @ 2023-09-24 19:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from danakj at orodu dot net ---
Thank you =)

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

end of thread, other threads:[~2023-09-24 19:13 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 17:38 [Bug c++/99631] New: decltype of non-type template-parameter shouldn't be const johelegp at gmail dot com
2021-03-18 13:20 ` [Bug c++/99631] " redi at gcc dot gnu.org
2021-03-18 13:48 ` jakub at gcc dot gnu.org
2021-03-18 23:44 ` johelegp at gmail dot com
2021-11-09 17:23 ` n60wb42d2 at relay dot firefox.com
2022-09-26  1:46 ` johelegp at gmail dot com
2022-09-26  1:47 ` johelegp at gmail dot com
2022-12-26 17:10 ` pinskia at gcc dot gnu.org
2023-09-15 17:38 ` ppalka at gcc dot gnu.org
2023-09-15 17:39 ` ppalka at gcc dot gnu.org
2023-09-15 17:41 ` ppalka at gcc dot gnu.org
2023-09-19 12:21 ` cvs-commit at gcc dot gnu.org
2023-09-24 18:42 ` cvs-commit at gcc dot gnu.org
2023-09-24 18:44 ` ppalka at gcc dot gnu.org
2023-09-24 19:13 ` danakj at orodu dot net

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