This is the mail archive of the
mailing list for the GCC project.
Two class definitions in different translation units
- From: Alex Markin <alexanius at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 28 Oct 2014 13:33:53 +0400
- Subject: Two class definitions in different translation units
- Authentication-results: sourceware.org; auth=none
I have a question about "One definition rule" for classes in different
translation units and gcc behaviour. Let us have the following
void foo(void * a)
a = new A;
void foo(void * a);
void bar(void * a)
a = new A;
void bar(void * a);
void * a;
And now let us see the gcc behaviour (I've tested with gcc-4.6.3 and gcc-4.9.1):
$ g++ *cpp && ./a.out
$ g++ *cpp -O1 && ./a.out
As far as I understand the main issue here is that class A has
external linkage and linker do not analyse the fields of class, it
just watches class A by name. And the example itself breaks `3.2 One
> â each definition of D shall consist of the same sequence of tokens
And now my questions:
* am I right with the understanding of situation and the example is UB?
* if two definitions had the same fields and the same constructors,
should the program be correct?
* is correct gcc behaviour with `-O1' a coincidence, or it detects
another class anyway?
* does it make sense to give a warning in that case?