This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/25316] New: POD structures can have
- From: "mrs at apple dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Dec 2005 20:48:25 -0000
- Subject: [Bug c++/25316] New: POD structures can have
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
A user reported that this:
mrs $ cat > t98.c
struct X {
int a, b;
X() : a(0), b(0) {}
};
static void f(const char *s, ...);
int main()
{
X x;
f("foo!", x);
return 0;
}
works on other C++ compilers (Metroworks), but on gcc:
mrs $ ./g++ -B./ -c t98.c
t98.c: In function 'int main()':
t98.c:11: warning: cannot pass objects of non-POD type 'struct X' through
'...'; call will abort at runtime
This, according the a reading of the standard is a POD type, no, really. :-)
Curious though, the same misreading of the text was done by the author of:
3 It is possible to transfer into a block, but not in a way that
bypasses declarations with initialization. A program that jumps77)
from a point where a local variable with automatic storage duration is
not in scope to a point where it is in scope is ill-formed unless the
variable has POD type (_basic.types_) and is declared without an ini-
tializer (_dcl.init_).
as the intent was to not bypass a constructor call.
Also curious is the wording:
To default-initialize an object of type T means:
--if T is a non-POD class type (clause _class_), the default construc-
tor for T is called (and the initialization is ill-formed if T has
no accessible default constructor);
which again reinforces the idea that only non-PODs can have default
constructors called.
Seems like we need a DR to clarify this, if one doesn't aready exist, and then
to fix up the compiler, if any fixups need to be done. I'd expect that the
compiler behavior is correct, but until DRed.
--
Summary: POD structures can have
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mrs at apple dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25316