This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66316] Usage of wrong template function for classes in different modules but having the same name
- From: "glisse at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 28 May 2015 05:33:25 +0000
- Subject: [Bug c++/66316] Usage of wrong template function for classes in different modules but having the same name
- Auto-submitted: auto-generated
- References: <bug-66316-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66316
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Alexander Trufanov from comment #0)
> Application has two .cpp modules. Let's say 1.cpp and 2.cpp.
> In each module there is a definition of struct N. Name N is the same for
> both. So we have two different structure declarations with the same name N.
> Compiler gives ok for such naming as they are not exposed from their modules
> and used internally in them. No namespaces are used.
>
> And structures have different number of fields. One has 1 field and another
> is 6 fields long.
You are violating the One Definition Rule, that's a bug in your program. If you
want names to be local, you can use an anonymous namespace.
Note that the word "module" in unclear. Those are two translation units. If you
compile them into separate shared libraries (for instance), using private
visibility could also help.