This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8797: g++ accepts in-class initialization of non-integral static member
- From: bangerth at ticam dot utexas dot edu
- To: gcc-gnats at gcc dot gnu dot org
- Date: 3 Dec 2002 15:43:36 -0000
- Subject: c++/8797: g++ accepts in-class initialization of non-integral static member
- Reply-to: bangerth at ticam dot utexas dot edu
>Number: 8797
>Category: c++
>Synopsis: g++ accepts in-class initialization of non-integral static member
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: accepts-illegal
>Submitter-Id: net
>Arrival-Date: Tue Dec 03 07:46:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Wolfgang Bangerth
>Release: unknown-1.0
>Organization:
>Environment:
2.95 through 3.3CVS, Linux (but front end matter anyway)
>Description:
Based on the discussion on PR 8778 (to be found in the audit
trail of that report):
gcc accepts this although the standard says that only
integral _scalars_ can be initialized in-class:
-----------------------------
struct A {
static const int i[] = { 1,2 };
};
-----------------------------
I _do_ get a warning if I use -pedantic. However, I maintain
that I should get an unconditional _error_ instead.
On the other hand, if this is a gcc extension, it should
- be documented in the manual
- generate an _error_ on -pedantic -ansi
To make things a little worse: templatizing the class like
---------------------------------------
template <int> struct A {
static const int i[] = { 1,2 };
};
template struct A<1>;
---------------------------------------
yields the following, slightly convoluted error message
stating the same content twice in different words:
tmp/g> /home/bangerth/bin/gcc-3.3-pre/bin/c++ -pedantic -ansi -c x.cc
x.cc:2: warning: ISO C++ forbids initialization of member constant `i' of
non-integral type `const int[]'
x.cc: In instantiation of `A<1>':
x.cc:5: instantiated from here
x.cc:2: warning: ISO C++ forbids initialization of member constant `A<1>::i' of
non-integral type `const int[2]'
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: