This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/50455] duplicate class/constructor silently accepted, wrong constructor linked
- From: "eda-qa at disemia dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 19 Sep 2011 12:20:24 +0000
- Subject: [Bug c++/50455] duplicate class/constructor silently accepted, wrong constructor linked
- Auto-submitted: auto-generated
- References: <bug-50455-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50455
--- Comment #1 from eda-qa at disemia dot com 2011-09-19 12:20:24 UTC ---
The compiler/linker is silently ignoring that a class has been defined twice
and this results in the linker linking to the incorrect constructor at
instantiation time.
This was found in a large set of libraries, but the two attached files
reproduce the same problem.
Reproduce:
- Compile a program using the attached files and the instantiation in main()
will use the wrong constructor.
g++ -o test main.cpp duplicate.cpp
Now, with optimizations the correct constructor is used, presumably since it is
inlined and thus not subject to linking:
g++ -O3 -o test main.cpp duplicate.cpp
NOTE: The code is *invalid* but emits no diagnostic as one would expect. The
issue is thus that the linker would be expected to emit a diagnostic message,
likely an error about duplicate symbol.