Bug 32056 - g++ does not detect non-integral in-class initializer
g++ does not detect non-integral in-class initializer
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2001-03-16 23:29 EST by Wagner T. Correa
Modified: 2007-04-18 12:32 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2001-03-16 23:29:47 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Wagner T. Correa 2001-03-16 23:29:44 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.2.16-22smp i686)

g++ fails to detect an illegal attempt to initialize a non-integral static
const member of a class inside the class declaration.

Reproducible: Always
Steps to Reproduce:
The following piece of code should generate an error:

#include <stdio.h>

class A {
	const static int N = 10; // OK
	const static float EPS = 0.0001; // illegal

const int A::N;
const float A::EPS;

int main()
	const int *pi = &A::N;
	printf("%d %d\n", A::N, *pi);

	const float *pf = &A::EPS;
	printf("%g %g\n", A::EPS, *pf);

	return 0;


Actual Results:  Currently, g++ (gcc-2.96-69) will accept that piece of
code, and produce an executable.

Expected Results:  g++ should abort compilation with an error.

See page 249 of  Bjarne Stroustrup, "The C++ Programming Language", Special
Edition, 2000.
Comment 1 Jakub Jelinek 2001-03-19 06:29:10 EST
No, it does detect it, but handles this as an extension to the standard.
If you want a warning, simply run g++ with -pedantic, if you want this to be
an error, run with -pedantic-errors:
g++ -pedantic-errors test.C
test.C:6: ISO C++ forbids initialization of member constant `EPS' of
non-integral type `const float'

Note You need to log in before you can comment on or make changes to this bug.