This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/19968] [3.3/3.4/4.0/4.1 Regression] Warning omitted for non-derived classes


------- Additional Comments From bangerth at dealii dot org  2005-03-02 21:54 -------
Correct. The class without inheritance doesn't need a constructor 
since objects of this type can be initialized using a brace-enclosed 
list. The class with inheritance is not POD, so it can't be initialized 
that way and needs a constructor. This should demonstrate this: 
----------------- 
struct B {}; 
 
struct A1 : B { const int i; }; 
struct A2     { const int i; }; 
 
A1 a1 = { 1 }; // not ok 
A2 a2 = { 1 }; // ok 
----------------- 
g/x> /home/bangerth/bin/gcc-3.4.4-pre/bin/c++ -W -Wall -ansi -pedantic -c x.cc 
x.cc:3: warning: non-static const member `const int A1::i' in class without a 
constructor 
x.cc:6: error: `a1' must be initialized by constructor, not by `{...}' 
 
This is therefore not a bug but correct behavior. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19968


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]