public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19246] New: Cannot instansate const struct without constructor.
@ 2005-01-03 22:53 chris at bubblescope dot net
  2005-01-03 22:55 ` [Bug c++/19246] Cannot instantiate " pcarlini at suse dot de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: chris at bubblescope dot net @ 2005-01-03 22:53 UTC (permalink / raw)
  To: gcc-bugs

The following code fails to compile. I believe (although I'm not positive) it
should:

struct S {};
const S s;

Notes:
The code doesn't compile with "struct S {int i;};", so the problem isn't an
empty struct.
The following variants do compile:

struct S{ S(){} };
const S s;

struct S {};
const S s = S();

Note that:
struct S {};
const S s();

does compile, but doesn't declare s as an S, but as a void function returning
const S.

This does compile in vc++7.1 (not that that means it's right!)

PS Yes I realise this construct is almost entirely useless, I came across it
while writing a testcase.

-- 
           Summary: Cannot instansate const struct without constructor.
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chris at bubblescope dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19246


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

* [Bug c++/19246] Cannot instantiate const struct without constructor.
  2005-01-03 22:53 [Bug c++/19246] New: Cannot instansate const struct without constructor chris at bubblescope dot net
@ 2005-01-03 22:55 ` pcarlini at suse dot de
  2005-01-04  0:45 ` pinskia at gcc dot gnu dot org
  2005-01-04  3:48 ` giovannibajo at libero dot it
  2 siblings, 0 replies; 4+ messages in thread
From: pcarlini at suse dot de @ 2005-01-03 22:55 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Cannot instansate const     |Cannot instantiate const
                   |struct without constructor. |struct without constructor.


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19246


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

* [Bug c++/19246] Cannot instantiate const struct without constructor.
  2005-01-03 22:53 [Bug c++/19246] New: Cannot instansate const struct without constructor chris at bubblescope dot net
  2005-01-03 22:55 ` [Bug c++/19246] Cannot instantiate " pcarlini at suse dot de
@ 2005-01-04  0:45 ` pinskia at gcc dot gnu dot org
  2005-01-04  3:48 ` giovannibajo at libero dot it
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-04  0:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-04 00:45 -------
Hmm, comeu C++ also rejects it:
"ComeauTest.c", line 2: error: const variable "s" requires an initializer -- class
          "S" has no explicitly declared default constructor
  const S s;
           ^

"ComeauTest.c", line 2: warning: variable "s" was declared but never referenced
  const S s;

Note VC++ does not reject non standard C++ by default.
You can try the comeau C++ online by:
<http://www.comeaucomputing.com/tryitout/>.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19246


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

* [Bug c++/19246] Cannot instantiate const struct without constructor.
  2005-01-03 22:53 [Bug c++/19246] New: Cannot instansate const struct without constructor chris at bubblescope dot net
  2005-01-03 22:55 ` [Bug c++/19246] Cannot instantiate " pcarlini at suse dot de
  2005-01-04  0:45 ` pinskia at gcc dot gnu dot org
@ 2005-01-04  3:48 ` giovannibajo at libero dot it
  2 siblings, 0 replies; 4+ messages in thread
From: giovannibajo at libero dot it @ 2005-01-04  3:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-01-04 03:48 -------
The standard is pretty clear about this, in [dcl.init]/9:

If no initializer is specified for an object, and the object is of (possibly  
cv-qualified) non-POD class type (or array thereof), the object shall be  
default-initialized; if the object is of const-qualified type, the underlying 
class type shall have a user-declared default constructor. Otherwise, if no 
initializer is specified for a non-static object, the object and its 
subobjects, if any, have an indeterminate initial value[90]; if the object or  
any of its subobjects are of const-qualified type, the program is ill-formed.

[90] This does not apply to aggregate objects with automatic storage duration  
initialized with an incomplete brace-enclosed initializer-list; see 
[dcl.init.aggr].


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19246


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

end of thread, other threads:[~2005-01-04  3:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-03 22:53 [Bug c++/19246] New: Cannot instansate const struct without constructor chris at bubblescope dot net
2005-01-03 22:55 ` [Bug c++/19246] Cannot instantiate " pcarlini at suse dot de
2005-01-04  0:45 ` pinskia at gcc dot gnu dot org
2005-01-04  3:48 ` giovannibajo at libero dot it

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