public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: gonz@ratloop.com
To: gcc-gnats@gcc.gnu.org
Subject: c++/10634: in-class initialization of static data members no longer allowed
Date: Tue, 06 May 2003 01:06:00 -0000	[thread overview]
Message-ID: <20030506005801.22852.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2003-05-06  1:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-06  1:06 gonz [this message]
2003-05-06  1:50 giovannibajo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030506005801.22852.qmail@sources.redhat.com \
    --to=gonz@ratloop.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).