diff options
author | Marek Polacek <polacek@redhat.com> | 2022-03-23 17:12:29 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-03-25 10:13:52 -0400 |
commit | d0b938a7612fb7acf1f181da9577235c83ede59e (patch) | |
tree | 74058c5a3bce65a7470ade9b3b98773df09c78fc /gcc/cp/constexpr.cc | |
parent | 8570cce7c705f2ec3ffaeb8e47d58af22a075ebd (diff) | |
download | gcc-d0b938a7612fb7acf1f181da9577235c83ede59e.zip gcc-d0b938a7612fb7acf1f181da9577235c83ede59e.tar.gz gcc-d0b938a7612fb7acf1f181da9577235c83ede59e.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp/constexpr.cc')
0 files changed, 0 insertions, 0 deletions