public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40076] New: g++ should not permit types to be defined in compound literals
@ 2009-05-08 21:36 ian at airs dot com
2009-05-08 21:42 ` [Bug c++/40076] " pinskia at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: ian at airs dot com @ 2009-05-08 21:36 UTC (permalink / raw)
To: gcc-bugs
This is invalid C++:
struct s1 { int i; } *p;
int i = ((struct s2 { int j; } *)p)->j;
foo.cc:2: error: types may not be defined in casts
By analogy, this should be invalid C++:
int i = (struct s3 { int j; }) { 1 }.j;
Currently g++ accepts it. Compound literals are an extension to C++, so there
are no documented rules about them. However, it seems to be that when it comes
to defining new types, they should be consistent with casts.
--
Summary: g++ should not permit types to be defined in compound
literals
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ian at airs dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <bug-40076-4@http.gcc.gnu.org/bugzilla/>]
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
[not found] <bug-40076-4@http.gcc.gnu.org/bugzilla/>
@ 2012-05-02 20:04 ` manu at gcc dot gnu.org
2012-05-02 20:14 ` joseph at codesourcery dot com
2012-05-02 20:21 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-02 20:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-05-02
CC| |manu at gcc dot gnu.org
Ever Confirmed|0 |1
--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-02 20:04:08 UTC ---
I think this is confirmed. Clang prints:
pr40076.cc:1:17: error: 's3' can not be defined in a type specifier
int i = (struct s3 { int j; }) { 1 }.j;
^
1 error generated.
for both C and C++.
GCC prints:
pr40076.cc:1:17: error: initializer element is not constant
int i = (struct s3 { int j; }) { 1 }.j;
^
which is less clear.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
[not found] <bug-40076-4@http.gcc.gnu.org/bugzilla/>
2012-05-02 20:04 ` manu at gcc dot gnu.org
@ 2012-05-02 20:14 ` joseph at codesourcery dot com
2012-05-02 20:21 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 7+ messages in thread
From: joseph at codesourcery dot com @ 2012-05-02 20:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
--- Comment #5 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-05-02 20:13:02 UTC ---
On Wed, 2 May 2012, manu at gcc dot gnu.org wrote:
> I think this is confirmed. Clang prints:
>
> pr40076.cc:1:17: error: 's3' can not be defined in a type specifier
> int i = (struct s3 { int j; }) { 1 }.j;
> ^
> 1 error generated.
>
> for both C and C++.
That's correct for C++ (by the analogy discussed in this bug report), but
not for C.
> pr40076.cc:1:17: error: initializer element is not constant
> int i = (struct s3 { int j; }) { 1 }.j;
> ^
>
> which is less clear.
That's a correct error for C, however; C allows types to be defined like
that in sizeof, casts and compound literals, but that initializer is not
(required to be) constant in C standard terms.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/40076] g++ should not permit types to be defined in compound literals
[not found] <bug-40076-4@http.gcc.gnu.org/bugzilla/>
2012-05-02 20:04 ` manu at gcc dot gnu.org
2012-05-02 20:14 ` joseph at codesourcery dot com
@ 2012-05-02 20:21 ` manu at gcc dot gnu.org
2 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu.org @ 2012-05-02 20:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40076
--- Comment #6 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-05-02 20:20:53 UTC ---
(In reply to comment #5)
> That's correct for C++ (by the analogy discussed in this bug report), but
> not for C.
My fault. Clang pays more attention to the file extension than to the driver
used. The correct output for C is:
test.c:1:9: error: initializer element is not a compile-time constant
int i = (struct s3 { int j; }) { 1 }.j;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated
which makes the error clearer than in gcc because of the caret location and the
range (plus the beautiful colors ;-).
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-05-02 20:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-08 21:36 [Bug c++/40076] New: g++ should not permit types to be defined in compound literals ian at airs dot com
2009-05-08 21:42 ` [Bug c++/40076] " pinskia at gcc dot gnu dot org
2009-05-08 21:51 ` pinskia at gcc dot gnu dot org
2009-05-08 22:19 ` ian at airs dot com
[not found] <bug-40076-4@http.gcc.gnu.org/bugzilla/>
2012-05-02 20:04 ` manu at gcc dot gnu.org
2012-05-02 20:14 ` joseph at codesourcery dot com
2012-05-02 20:21 ` manu at gcc dot gnu.org
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).