public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19968] New: Warning omitted for non-derived classes
@ 2005-02-15 13:29 reichelt at gcc dot gnu dot org
2005-02-15 14:14 ` [Bug c++/19968] [3.3/3.4/4.0 Regression] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-02-15 13:29 UTC (permalink / raw)
To: gcc-bugs
Compiling the following code snippet with -Wextra, a sensible warning
is issued:
======================
struct B {};
struct A : B
{
const int i;
};
======================
warn.cc:5: warning: non-static const member 'const int A::i' in class without a
constructor
However, if A is not a derived class, the warning is not given:
======================
struct A
{
const int i;
};
======================
This is at least inconsistent. I'd vote for a warning in the second case, too.
--
Summary: Warning omitted for non-derived classes
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Keywords: diagnostic, monitored
Severity: enhancement
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reichelt at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19968
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/19968] Warning omitted for non-derived classes
2005-02-15 13:29 [Bug c++/19968] New: Warning omitted for non-derived classes reichelt at gcc dot gnu dot org
2005-02-15 14:14 ` [Bug c++/19968] [3.3/3.4/4.0 Regression] " pinskia at gcc dot gnu dot org
@ 2005-02-15 14:14 ` reichelt at gcc dot gnu dot org
2005-03-02 21:36 ` [Bug c++/19968] [3.3/3.4/4.0/4.1 Regression] " aoliva at gcc dot gnu dot org
2005-03-02 21:54 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2005-02-15 14:14 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From reichelt at gcc dot gnu dot org 2005-02-15 01:29 -------
Btw, the warning in the second case is missing since gcc 3.3.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19968
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/19968] [3.3/3.4/4.0 Regression] Warning omitted for non-derived classes
2005-02-15 13:29 [Bug c++/19968] New: Warning omitted for non-derived classes reichelt at gcc dot gnu dot org
@ 2005-02-15 14:14 ` pinskia at gcc dot gnu dot org
2005-02-15 14:14 ` [Bug c++/19968] " reichelt at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-15 14:14 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-02-15 01:32 -------
: Search converges between 2002-10-02-trunk (#92) and 2002-10-03-trunk (#93).
Confirmed.
--
What |Removed |Added
----------------------------------------------------------------------------
Severity|enhancement |minor
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2005-02-15 01:32:08
date| |
Summary|Warning omitted for non- |[3.3/3.4/4.0 Regression]
|derived classes |Warning omitted for non-
| |derived classes
Target Milestone|--- |3.4.4
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19968
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/19968] [3.3/3.4/4.0/4.1 Regression] Warning omitted for non-derived classes
2005-02-15 13:29 [Bug c++/19968] New: Warning omitted for non-derived classes reichelt at gcc dot gnu dot org
2005-02-15 14:14 ` [Bug c++/19968] [3.3/3.4/4.0 Regression] " pinskia at gcc dot gnu dot org
2005-02-15 14:14 ` [Bug c++/19968] " reichelt at gcc dot gnu dot org
@ 2005-03-02 21:36 ` aoliva at gcc dot gnu dot org
2005-03-02 21:54 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: aoliva at gcc dot gnu dot org @ 2005-03-02 21:36 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From aoliva at gcc dot gnu dot org 2005-03-02 21:36 -------
I think this is correct behavior. Without inheritance, the struct is POD, so
different rules apply.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19968
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/19968] [3.3/3.4/4.0/4.1 Regression] Warning omitted for non-derived classes
2005-02-15 13:29 [Bug c++/19968] New: Warning omitted for non-derived classes reichelt at gcc dot gnu dot org
` (2 preceding siblings ...)
2005-03-02 21:36 ` [Bug c++/19968] [3.3/3.4/4.0/4.1 Regression] " aoliva at gcc dot gnu dot org
@ 2005-03-02 21:54 ` bangerth at dealii dot org
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2005-03-02 21:54 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-03-02 21:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-15 13:29 [Bug c++/19968] New: Warning omitted for non-derived classes reichelt at gcc dot gnu dot org
2005-02-15 14:14 ` [Bug c++/19968] [3.3/3.4/4.0 Regression] " pinskia at gcc dot gnu dot org
2005-02-15 14:14 ` [Bug c++/19968] " reichelt at gcc dot gnu dot org
2005-03-02 21:36 ` [Bug c++/19968] [3.3/3.4/4.0/4.1 Regression] " aoliva at gcc dot gnu dot org
2005-03-02 21:54 ` bangerth at dealii dot org
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).