Bug 39188

Summary: gcc improperly errors on const declaration
Product: [Retired] Red Hat Linux Reporter: Omnifarious <hopper>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-05-05 05:36:00 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Omnifarious 2001-05-05 05:35:57 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.3 i686; en-US; 0.8.1) Gecko/20010421

Description of problem:
If you have a const variable for a type with no constructors at all (i.e.
only the compiler supplied default constructor), it tells you the variable
is an uninitialized const.


How reproducible:
Always

Steps to Reproduce:
Given this program:
----  simpletest.cpp
struct Fred { };

static const Fred fred;
----
and this command line:
g++ -pipe -march=athlon -g simpletest.cpp
----
I get this erroneous error:
simpletest.cpp:3: uninitialized const `fred'


Actual Results:  simpletest.cpp:3: uninitialized const `fred'


Expected Results:  /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o:
In function `_start':
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18):
undefined reference to `main'
collect2: ld returned 1 exit status



Additional info:

This is actually a heavily modified 7.0 system.  But, I do have all of the
gcc-2.96-81 packages, including cpp.

Comment 1 Jakub Jelinek 2001-05-05 16:51:05 UTC
ISO C++ explicitely disallows this, read [dcl.init]/9:
If no initializer is specified for an object ...
... if the object is of const-qualified type, the underlying class type shall
have a user-defined default constructor.