[Bug c++/104944] incorrect alignas(void) accepted (with warning if templated)
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Mar 16 13:08:06 GMT 2022
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.
More information about the Gcc-bugs
mailing list