public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10634: in-class initialization of static data members no longer allowed
@ 2003-05-06  1:50 giovannibajo
  0 siblings, 0 replies; 2+ messages in thread
From: giovannibajo @ 2003-05-06  1:50 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, gonz, nobody

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 526 bytes --]

Synopsis: in-class initialization of static data members no longer allowed

State-Changed-From-To: open->closed
State-Changed-By: bajo
State-Changed-When: Tue May  6 01:50:09 2003
State-Changed-Why:
    Not a bug. GCC does the right thing now: §9.4.2 specifies
    that only static data member of const integral or const
    enumeration type can be initialized at declaration time.
    "unsigned char* const" is not a const integral type.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10634


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

* c++/10634: in-class initialization of static data members no longer allowed
@ 2003-05-06  1:06 gonz
  0 siblings, 0 replies; 2+ messages in thread
From: gonz @ 2003-05-06  1:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         10634
>Category:       c++
>Synopsis:       in-class initialization of static data members no longer allowed
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 06 01:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Pete Gonzalez
>Release:        gcc-3.2.3 and 3.3 (20030428 prerelease)
>Organization:
>Environment:
Debian Linux (testing - "sarge")
>Description:
The following code compiled without problems under GCC 3.2.1 and GCC 2.95.4:

struct Struct {
  static unsigned char *const pointer = (unsigned char*)0x123;
};

However, with GCC version 3.2.3 and 3.3 it produces the error message "invalid in-class initialization of static data member of non-integral type `unsigned char* const'".

The code can be made to compile by moving the definition into the .cpp file; however, this is suboptimal because the constant can no longer be inlined.

This error message is coming from check_static_variable_definition() in gcc/cp/decl.c.  The comment there reads:

  /* Motion 10 at San Diego: If a static const integral data member is
     initialized with an integral constant expression, the initializer
     may appear either in the declaration (within the class), or in
     the definition, but not both.  If it appears in the class, the
     member is a member constant.  The file-scope definition is always
     required.  */

Since the "but not both" condition is not applicable in the above example, this looks like a bug.
>How-To-Repeat:
Copy the above code into test.cpp and then run "gcc -c test.cpp"
>Fix:
In gcc/cp/decl.c, replace "if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)" with "if (false)"  :-)
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2003-05-06  1:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-06  1:50 c++/10634: in-class initialization of static data members no longer allowed giovannibajo
  -- strict thread matches above, loose matches on Subject: below --
2003-05-06  1:06 gonz

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