public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13
@ 2024-01-28 15:21 de34 at live dot cn
2024-01-28 15:28 ` [Bug c++/113638] " de34 at live dot cn
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: de34 at live dot cn @ 2024-01-28 15:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
Bug ID: 113638
Summary: Array bounds of variable templates are not correctly
deduced from initializers since GCC13
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Keywords: accepts-invalid, rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: de34 at live dot cn
Target Milestone: ---
The following code snippet is incorrectly processed since C++13.
Godbolt link: https://godbolt.org/z/xjEqnqodj
```
#include <type_traits>
template<int ...Is>
constexpr int my_array[]{Is...};
static_assert(std::is_same_v<decltype(my_array<1, 2, 3, 4, 5>), const int[5]>);
// rejected since GCC13
static_assert(sizeof(my_array<1, 2, 3, 4, 5>) == sizeof(int) * 5); // rejected
since GCC13
static_assert(std::is_same_v<decltype(my_array<1, 2, 3, 4, 5>), const int[]>);
// passes since GCC13, but should not
```
It seems that GCC gives up deducing the array bounds from initializers of
variable templates since GCC13.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] Array bounds of variable templates are not correctly deduced from initializers since GCC13
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
@ 2024-01-28 15:28 ` de34 at live dot cn
2024-01-28 18:56 ` [Bug c++/113638] [13/14 Regression] " pinskia at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: de34 at live dot cn @ 2024-01-28 15:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
--- Comment #1 from Jiang An <de34 at live dot cn> ---
> The following code snippet is incorrectly processed since C++13.
Typo: this should be "since GCC13".
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
2024-01-28 15:28 ` [Bug c++/113638] " de34 at live dot cn
@ 2024-01-28 18:56 ` pinskia at gcc dot gnu.org
2024-01-28 21:51 ` [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof pinskia at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-28 18:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |13.3
Summary|Array bounds of variable |[13/14 Regression] Array
|templates are not correctly |bounds of variable
|deduced from initializers |templates are not correctly
|since GCC13 |deduced from initializers
| |since GCC13
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
2024-01-28 15:28 ` [Bug c++/113638] " de34 at live dot cn
2024-01-28 18:56 ` [Bug c++/113638] [13/14 Regression] " pinskia at gcc dot gnu.org
@ 2024-01-28 21:51 ` pinskia at gcc dot gnu.org
2024-01-29 15:58 ` ppalka at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-28 21:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2024-01-28
Status|UNCONFIRMED |NEW
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Simplified testcase:
```
template<int ...Is>
constexpr int my_array[]{Is...};
constexpr auto t1 = my_array<2>;
static_assert(sizeof(my_array<1>) == sizeof(int) * 1);
```
If we change the t1 variable definition to use `my_array<1>` instead of
`my_array<2>`, then the sizeof works.
It seems like we are not fully instantiating the template variable when used
inside a decltype/sizeof to figure out the array bounds.
An obvious workaround is to do:
```
template<int ...Is>
constexpr int my_array[sizeof...(Is)]{Is...};
```
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
` (2 preceding siblings ...)
2024-01-28 21:51 ` [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof pinskia at gcc dot gnu.org
@ 2024-01-29 15:58 ` ppalka at gcc dot gnu.org
2024-01-29 21:33 ` ppalka at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-01-29 15:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|needs-bisection |
CC| |ppalka at gcc dot gnu.org
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Started with r13-2540-g4db3cb781c3553. If we remove the constexpr then it
seems we never accepted the testcase, so this is only a regression for
constexpr variable templates, but a proper fix will likely cover the
non-constexpr case too.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
` (3 preceding siblings ...)
2024-01-29 15:58 ` ppalka at gcc dot gnu.org
@ 2024-01-29 21:33 ` ppalka at gcc dot gnu.org
2024-01-29 21:44 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-01-29 21:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
This seems to be the variable template version of
https://cplusplus.github.io/CWG/issues/408.html, the resolution of which
predated variable templates.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
` (4 preceding siblings ...)
2024-01-29 21:33 ` ppalka at gcc dot gnu.org
@ 2024-01-29 21:44 ` pinskia at gcc dot gnu.org
2024-01-29 22:09 ` ppalka at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-29 21:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #4)
> This seems to be the variable template version of
> https://cplusplus.github.io/CWG/issues/408.html, the resolution of which
> predated variable templates.
Note this works though (which I thought would be able the same, this is another
workaround):
```
template<int ...Is>
struct X
{
static int s[];
};
template<int ...Is>
int X<Is...>::s[]={Is...};
static_assert(sizeof(X<1>::s) == sizeof(int) * 1, "");
```
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
` (5 preceding siblings ...)
2024-01-29 21:44 ` pinskia at gcc dot gnu.org
@ 2024-01-29 22:09 ` ppalka at gcc dot gnu.org
2024-02-01 21:41 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-01-29 22:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Indeed, looks like we implement CWG408 since r158075.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
` (6 preceding siblings ...)
2024-01-29 22:09 ` ppalka at gcc dot gnu.org
@ 2024-02-01 21:41 ` jason at gcc dot gnu.org
2024-02-02 3:22 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2024-02-01 21:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
` (7 preceding siblings ...)
2024-02-01 21:41 ` jason at gcc dot gnu.org
@ 2024-02-02 3:22 ` cvs-commit at gcc dot gnu.org
2024-02-02 15:57 ` cvs-commit at gcc dot gnu.org
2024-02-02 16:12 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-02 3:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:0b786ff38ab398087820d91241e030a28c451df9
commit r14-8726-g0b786ff38ab398087820d91241e030a28c451df9
Author: Jason Merrill <jason@redhat.com>
Date: Thu Feb 1 16:54:39 2024 -0500
c++: variable template array of unknown bound [PR113638]
When we added variable templates, we didn't extend the
VAR_HAD_UNKNOWN_BOUND
handling for class template static data members to handle them as well.
PR c++/113638
gcc/cp/ChangeLog:
* cp-tree.h: Adjust comment.
* pt.cc (instantiate_template): Set VAR_HAD_UNKNOWN_BOUND for
variable template.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ-array1.C: New test.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
` (8 preceding siblings ...)
2024-02-02 3:22 ` cvs-commit at gcc dot gnu.org
@ 2024-02-02 15:57 ` cvs-commit at gcc dot gnu.org
2024-02-02 16:12 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-02 15:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:69f04177fed0de2c5f121b7607b7b59d3ba93451
commit r13-8272-g69f04177fed0de2c5f121b7607b7b59d3ba93451
Author: Jason Merrill <jason@redhat.com>
Date: Thu Feb 1 16:54:39 2024 -0500
c++: variable template array of unknown bound [PR113638]
When we added variable templates, we didn't extend the
VAR_HAD_UNKNOWN_BOUND
handling for class template static data members to handle them as well.
PR c++/113638
gcc/cp/ChangeLog:
* cp-tree.h: Adjust comment.
* pt.cc (instantiate_template): Set VAR_HAD_UNKNOWN_BOUND for
variable template.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ-array1.C: New test.
(cherry picked from commit 0b786ff38ab398087820d91241e030a28c451df9)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
` (9 preceding siblings ...)
2024-02-02 15:57 ` cvs-commit at gcc dot gnu.org
@ 2024-02-02 16:12 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2024-02-02 16:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113638
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 13.3/14.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-02-02 16:12 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-28 15:21 [Bug c++/113638] New: Array bounds of variable templates are not correctly deduced from initializers since GCC13 de34 at live dot cn
2024-01-28 15:28 ` [Bug c++/113638] " de34 at live dot cn
2024-01-28 18:56 ` [Bug c++/113638] [13/14 Regression] " pinskia at gcc dot gnu.org
2024-01-28 21:51 ` [Bug c++/113638] [13/14 Regression] Array bounds of variable templates are not correctly deduced from initializers since GCC13 inside a decltype/sizeof pinskia at gcc dot gnu.org
2024-01-29 15:58 ` ppalka at gcc dot gnu.org
2024-01-29 21:33 ` ppalka at gcc dot gnu.org
2024-01-29 21:44 ` pinskia at gcc dot gnu.org
2024-01-29 22:09 ` ppalka at gcc dot gnu.org
2024-02-01 21:41 ` jason at gcc dot gnu.org
2024-02-02 3:22 ` cvs-commit at gcc dot gnu.org
2024-02-02 15:57 ` cvs-commit at gcc dot gnu.org
2024-02-02 16:12 ` jason 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).