This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/54161] New: sizeof(void) expressions are accepted
- From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 02 Aug 2012 18:03:04 +0000
- Subject: [Bug c++/54161] New: sizeof(void) expressions are accepted
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: daniel.kruegler@googlemail.com
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.