public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54161] New: sizeof(void) expressions are accepted
@ 2012-08-02 18:03 daniel.kruegler at googlemail dot com
  2012-08-02 18:42 ` [Bug c++/54161] " paolo.carlini at oracle dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-08-02 18:03 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-08-06 10:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-02 18:03 [Bug c++/54161] New: sizeof(void) expressions are accepted daniel.kruegler at googlemail dot com
2012-08-02 18:42 ` [Bug c++/54161] " paolo.carlini at oracle dot com
2012-08-02 20:13 ` daniel.kruegler at googlemail dot com
2012-08-02 20:35 ` jason at gcc dot gnu.org
2012-08-02 21:11 ` paolo.carlini at oracle dot com
2012-08-03 14:20 ` jason at redhat dot com
2012-08-04 12:35 ` paolo.carlini at oracle dot com
2012-08-06  9:46 ` paolo.carlini at oracle dot com
2012-08-06 10:02 ` paolo.carlini at oracle dot com

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).