public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated)
@ 2022-03-16 0:10 gccbugbjorn at fahller dot se
2022-03-16 13:08 ` [Bug c++/104944] " redi at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: gccbugbjorn at fahller dot se @ 2022-03-16 0:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
Bug ID: 104944
Summary: incorrect alignas(void) accepted (with warning if
templated)
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gccbugbjorn at fahller dot se
Target Milestone: ---
The erroneous code:
struct alignas(void) S{};
Is accepted without any diagnostic with g++
(Compiler-Explorer-Build-gcc-98cd717fca9f21625b9c79c9231c2e909d1d93a3-binutils-2.36.1)
12.0.1 20220306 (experimental)
https://godbolt.org/z/q7das4G1W
With 'void' coming from a template, a confusing warning is issued:
template <typename T>
struct alignas(T) S {};
S<void> s;
The message is:
In instantiation of 'struct S<void>':
<source>:4:9: required from here
<source>:2:16: warning: invalid application of '__alignof__' to a void type
[-Wpointer-arith]
2 | struct alignas(T) S {};
| ^
This is not entirely incorrect, but I believe most programmers would recognize
that they have no `__alignof__` in their code, nor any pointer arithmetics.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
@ 2022-03-16 13:08 ` redi at gcc dot gnu.org
2022-03-16 13:13 ` [Bug c++/104944] [9/10/11/12 Regression] " redi at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-16 13:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-03-16
Status|UNCONFIRMED |NEW
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=85979
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Björn Fahller from comment #0)
> The erroneous code:
>
> struct alignas(void) S{};
>
> Is accepted without any diagnostic with g++
> (Compiler-Explorer-Build-gcc-98cd717fca9f21625b9c79c9231c2e909d1d93a3-
> binutils-2.36.1) 12.0.1 20220306 (experimental)
>
> https://godbolt.org/z/q7das4G1W
Confirmed.
> With 'void' coming from a template, a confusing warning is issued:
>
> template <typename T>
> struct alignas(T) S {};
>
> S<void> s;
>
> The message is:
>
> In instantiation of 'struct S<void>':
> <source>:4:9: required from here
> <source>:2:16: warning: invalid application of '__alignof__' to a void type
> [-Wpointer-arith]
> 2 | struct alignas(T) S {};
> | ^
This is accepted with a warning (rather than an error) because of the
https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html extension.
> This is not entirely incorrect, but I believe most programmers would
> recognize that they have no `__alignof__` in their code, nor any pointer
> arithmetics.
That's PR 85979.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] [9/10/11/12 Regression] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
2022-03-16 13:08 ` [Bug c++/104944] " redi at gcc dot gnu.org
@ 2022-03-16 13:13 ` redi at gcc dot gnu.org
2022-03-16 14:32 ` mpolacek at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2022-03-16 13:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|incorrect alignas(void) |[9/10/11/12 Regression]
|accepted (with warning if |incorrect alignas(void)
|templated) |accepted (with warning if
| |templated)
Known to fail| |12.0, 5.1.0
CC| |mpolacek at gcc dot gnu.org
Known to work| |4.9.4
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Before GCC 5.1 the non-template case was rejected:
104944.C:1:22: error: requested alignment is not an integer constant
struct alignas(void) S{};
^
That changed with r210262:
Author: Marek Polacek
Date: Fri May 9 09:24:37 2014
re PR c/50459 (alignof doesn't work on plain old constant, works with
expressions containing it)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] [9/10/11/12 Regression] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
2022-03-16 13:08 ` [Bug c++/104944] " redi at gcc dot gnu.org
2022-03-16 13:13 ` [Bug c++/104944] [9/10/11/12 Regression] " redi at gcc dot gnu.org
@ 2022-03-16 14:32 ` mpolacek at gcc dot gnu.org
2022-03-25 14:15 ` cvs-commit at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-16 14:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |9.5
Status|NEW |ASSIGNED
Priority|P3 |P2
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Mine then.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] [9/10/11/12 Regression] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
` (2 preceding siblings ...)
2022-03-16 14:32 ` mpolacek at gcc dot gnu.org
@ 2022-03-25 14:15 ` cvs-commit at gcc dot gnu.org
2022-03-25 14:18 ` [Bug c++/104944] [9/10/11 " mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-25 14:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:d0b938a7612fb7acf1f181da9577235c83ede59e
commit r12-7815-gd0b938a7612fb7acf1f181da9577235c83ede59e
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Mar 23 17:12:29 2022 -0400
c++: alignas and alignof void [PR104944]
I started looking into this PR because in GCC 4.9 we were able to
detect the invalid
struct alignas(void) S{};
but I broke it in r210262.
It's ill-formed code in C++:
[dcl.align]/3: "An alignment-specifier of the form alignas(type-id) has
the same effect as alignas(alignof(type-id))", and [expr.align]/1:
"The operand shall be a type-id representing a complete object type,
or an array thereof, or a reference to one of those types." and void
is not a complete type.
It's also invalid in C:
6.7.5: _Alignas(type-name) is equivalent to _Alignas(_Alignof(type-name))
6.5.3.4: "The _Alignof operator shall not be applied to a function type
or an incomplete type."
We have a GNU extension whereby we treat sizeof(void) as 1, but I assume
it doesn't apply to alignof, at least in C++. However, __alignof__(void)
is still accepted with a -Wpedantic warning.
We still say "invalid application of 'alignof'" rather than 'alignas' in
the
void diagnostic, but I felt that fixing that may not be suitable as part of
this patch. The "incomplete type" diagnostic still always prints
'__alignof__'.
PR c++/104944
gcc/cp/ChangeLog:
* typeck.cc (cxx_sizeof_or_alignof_type): Diagnose alignof(void).
(cxx_alignas_expr): Call cxx_sizeof_or_alignof_type with
complain == true.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/alignas20.C: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] [9/10/11 Regression] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
` (3 preceding siblings ...)
2022-03-25 14:15 ` cvs-commit at gcc dot gnu.org
@ 2022-03-25 14:18 ` mpolacek at gcc dot gnu.org
2022-03-29 1:46 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-25 14:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11/12 Regression] |[9/10/11 Regression]
|incorrect alignas(void) |incorrect alignas(void)
|accepted (with warning if |accepted (with warning if
|templated) |templated)
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far. I guess I might backport to 11 too.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] [9/10/11 Regression] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
` (4 preceding siblings ...)
2022-03-25 14:18 ` [Bug c++/104944] [9/10/11 " mpolacek at gcc dot gnu.org
@ 2022-03-29 1:46 ` cvs-commit at gcc dot gnu.org
2022-03-29 1:48 ` [Bug c++/104944] [9/10 " mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-29 1:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:fe641f6a44959ff8b9d9f7af11b8b806c5f1375a
commit r11-9714-gfe641f6a44959ff8b9d9f7af11b8b806c5f1375a
Author: Marek Polacek <polacek@redhat.com>
Date: Wed Mar 23 17:12:29 2022 -0400
c++: alignas and alignof void [PR104944]
I started looking into this PR because in GCC 4.9 we were able to
detect the invalid
struct alignas(void) S{};
but I broke it in r210262.
It's ill-formed code in C++:
[dcl.align]/3: "An alignment-specifier of the form alignas(type-id) has
the same effect as alignas(alignof(type-id))", and [expr.align]/1:
"The operand shall be a type-id representing a complete object type,
or an array thereof, or a reference to one of those types." and void
is not a complete type.
It's also invalid in C:
6.7.5: _Alignas(type-name) is equivalent to _Alignas(_Alignof(type-name))
6.5.3.4: "The _Alignof operator shall not be applied to a function type
or an incomplete type."
We have a GNU extension whereby we treat sizeof(void) as 1, but I assume
it doesn't apply to alignof, at least in C++. However, __alignof__(void)
is still accepted with a -Wpedantic warning.
We still say "invalid application of 'alignof'" rather than 'alignas' in
the
void diagnostic, but I felt that fixing that may not be suitable as part of
this patch. The "incomplete type" diagnostic still always prints
'__alignof__'.
PR c++/104944
gcc/cp/ChangeLog:
* typeck.c (cxx_sizeof_or_alignof_type): Diagnose alignof(void).
(cxx_alignas_expr): Call cxx_sizeof_or_alignof_type with
complain == true.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/alignas20.C: New test.
(cherry picked from commit d0b938a7612fb7acf1f181da9577235c83ede59e)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] [9/10 Regression] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
` (5 preceding siblings ...)
2022-03-29 1:46 ` cvs-commit at gcc dot gnu.org
@ 2022-03-29 1:48 ` mpolacek at gcc dot gnu.org
2022-03-29 1:49 ` mpolacek at gcc dot gnu.org
2022-12-30 22:28 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-29 1:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11 Regression] |[9/10 Regression] incorrect
|incorrect alignas(void) |alignas(void) accepted
|accepted (with warning if |(with warning if templated)
|templated) |
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] [9/10 Regression] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
` (6 preceding siblings ...)
2022-03-29 1:48 ` [Bug c++/104944] [9/10 " mpolacek at gcc dot gnu.org
@ 2022-03-29 1:49 ` mpolacek at gcc dot gnu.org
2022-12-30 22:28 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-03-29 1:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c++/104944] [9/10 Regression] incorrect alignas(void) accepted (with warning if templated)
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
` (7 preceding siblings ...)
2022-03-29 1:49 ` mpolacek at gcc dot gnu.org
@ 2022-12-30 22:28 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-30 22:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104944
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail|12.0 |11.2.0
Target Milestone|9.5 |11.3
Known to work| |11.3.0, 12.1.0
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-12-30 22:28 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 0:10 [Bug c++/104944] New: incorrect alignas(void) accepted (with warning if templated) gccbugbjorn at fahller dot se
2022-03-16 13:08 ` [Bug c++/104944] " redi at gcc dot gnu.org
2022-03-16 13:13 ` [Bug c++/104944] [9/10/11/12 Regression] " redi at gcc dot gnu.org
2022-03-16 14:32 ` mpolacek at gcc dot gnu.org
2022-03-25 14:15 ` cvs-commit at gcc dot gnu.org
2022-03-25 14:18 ` [Bug c++/104944] [9/10/11 " mpolacek at gcc dot gnu.org
2022-03-29 1:46 ` cvs-commit at gcc dot gnu.org
2022-03-29 1:48 ` [Bug c++/104944] [9/10 " mpolacek at gcc dot gnu.org
2022-03-29 1:49 ` mpolacek at gcc dot gnu.org
2022-12-30 22:28 ` pinskia 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).