http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54161
Bug #: 54161
Summary: sizeof(void) expressions are accepted
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
gcc 4.8.0 20120729 (experimental) accepts the following code even using the
following options:
-Wall -pedantic -ansi
with either of -std=c++98 or -std=c++0x
//----
void f();
void (&g())();
const int a = sizeof(void);
const int b = sizeof(void());
const int c = sizeof(f());
const int d = sizeof(g());
typedef char test[a + b + c + d > 0 ? 1 : -1];
//----
albeit issuing warnings:
"4|warning: invalid application of 'sizeof' to a void type [-Wpedantic]|
5|warning: invalid application of 'sizeof' to a function type [-Wpedantic]|
6|warning: invalid application of 'sizeof' to a void type [-Wpedantic]|
7|warning: invalid application of 'sizeof' to a function type [-Wpedantic]|
"
This code is ill-formed according to [expr.sizeof] p1:
"The sizeof operator shall not be applied to an expression that has function or
incomplete type, [..], to the parenthesized name of such types, or to an lvalue
that designates a bit-field."
and thus should be rejected.
The current behaviour is especially annoying, because such expression can occur
in SFINAE expression where corresponding template specializations are not
excluded from the set.