This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/82035] New: GCC picks wrong template method instantiation if there are same name classes in independent compilation units
- From: "denis at denivip dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 30 Aug 2017 13:32:05 +0000
- Subject: [Bug c++/82035] New: GCC picks wrong template method instantiation if there are same name classes in independent compilation units
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82035
Bug ID: 82035
Summary: GCC picks wrong template method instantiation if there
are same name classes in independent compilation units
Product: gcc
Version: 6.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: denis at denivip dot ru
Target Milestone: ---
Created attachment 42086
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42086&action=edit
A minimal set for reproducing the bug
If we have two independent compilation units (lets say PointsPusher.cpp and
WrongPointsPusher.cpp) and both internally use std::vector push_back method
with their own definitions of a class (lets say Point which has different size
in these definitions) then during the compilation of the second unit push_back
method will be taken from the first unit, leading to incorrect memory
allocations and vector size management.
Here is an example: PointsPusher defines Point as 3 float values,
WrongPointsPusher defines Point as 3 double values. If GCC compiled
WrongPointsPusher then during PointsPusher compilation std::vector push_back
method will be using incorrect size Point.
I assume that gcc simply takes previously cached version of the instantiated
template method and uses it in another unit despite different template
parameter (different class size).
GCC should instantiate template methods with classes of current compilation
unit event if there are same name classes in other independent units.
This bug is especially annoying for big teams where several developers could
use same name classes in their compilation units, and that would lead to weird
behaviour.
Depending on optimization level (-0) there's different amount of memory
reallocations, hence slighlty different behaviour (but always erroneous).
I've prepared a minimal set of source files with a makefile, so you could
easily see the issue.
The bug was noticed in:
* gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
* gcc version 6.3.0 20170519 (Ubuntu/Linaro 6.3.0-18ubuntu2~16.04)
In gcc 7.1 it seems to be ok.