public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32549]  New: Wrong template instance resolution among multiple object files.
@ 2007-06-29 17:44 opichals at seznam dot cz
  2007-06-29 17:46 ` [Bug c++/32549] " opichals at seznam dot cz
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: opichals at seznam dot cz @ 2007-06-29 17:44 UTC (permalink / raw)
  To: gcc-bugs

There seems to be something inconsistent in the g++ template
instantiation.

When a template is instantiated with an argument of the same
name in two object files in which the argument type is different
(unlike their names). It appears that even though that those
instances should have been distinct g++ resolves them into a
single one which appears to be wrong.

Please see the attached reproduction code. The code of the
template only prints the sizeof() of its (template) argument. 
The argument if places in a global namespace in each of the
object files is considered to be the same no matter of its
size or structure (as long as it is of the same name).

I have reproduced the gcc 3.4.6 and gcc 4.0.1 to behave the
same in this aspect (see the attached test output files).


-- 
           Summary: Wrong template instance resolution among multiple object
                    files.
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: opichals at seznam dot cz
 GCC build triplet: x86
  GCC host triplet: x86
GCC target triplet: x86


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32549


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/32549] Wrong template instance resolution among multiple object files.
  2007-06-29 17:44 [Bug c++/32549] New: Wrong template instance resolution among multiple object files opichals at seznam dot cz
@ 2007-06-29 17:46 ` opichals at seznam dot cz
  2007-06-29 19:46 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: opichals at seznam dot cz @ 2007-06-29 17:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from opichals at seznam dot cz  2007-06-29 17:45 -------
Created an attachment (id=13805)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13805&action=view)
Reproduction code and Makefile printing out results of the test

The log files gcc-4.1.0.make.log and gcc-3.4.6.make.log contain the 'make'
output from RHEL 4.0 Linux machine.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32549


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/32549] Wrong template instance resolution among multiple object files.
  2007-06-29 17:44 [Bug c++/32549] New: Wrong template instance resolution among multiple object files opichals at seznam dot cz
  2007-06-29 17:46 ` [Bug c++/32549] " opichals at seznam dot cz
@ 2007-06-29 19:46 ` pinskia at gcc dot gnu dot org
  2007-06-30 15:05 ` opichals at seznam dot cz
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-29 19:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-06-29 19:45 -------
I don't think this is a bug.
So we have in one TU:
typedef struct {
        char x[10];
} Argument;
And in the other:
typedef struct {
        char x[20];
} Argument;
--------------- cut ---------------
IIRC from my reading of the C++ standard, that Argument here has to be same
types accross TUs (the One Definition Rule).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32549


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/32549] Wrong template instance resolution among multiple object files.
  2007-06-29 17:44 [Bug c++/32549] New: Wrong template instance resolution among multiple object files opichals at seznam dot cz
  2007-06-29 17:46 ` [Bug c++/32549] " opichals at seznam dot cz
  2007-06-29 19:46 ` pinskia at gcc dot gnu dot org
@ 2007-06-30 15:05 ` opichals at seznam dot cz
  2007-09-08 23:53 ` bangerth at dealii dot org
  2007-09-17 11:36 ` opichals at seznam dot cz
  4 siblings, 0 replies; 6+ messages in thread
From: opichals at seznam dot cz @ 2007-06-30 15:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from opichals at seznam dot cz  2007-06-30 15:05 -------
I am not sure about the standard wording. But logically typedefs local
to a .cpp file should stay local to that file. They in fact are. However
the template instances are not.

If it should not be that way then the compiler should complain about such
conflicts in some way not to get the two confused at runtime. Especially in
huge application merges this is very critical.

note: I am sorry, will be out of reach for the next few weeks to discuss in
detail. I would appreciate any pointers or more detailed explanations you could
provide.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32549


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/32549] Wrong template instance resolution among multiple object files.
  2007-06-29 17:44 [Bug c++/32549] New: Wrong template instance resolution among multiple object files opichals at seznam dot cz
                   ` (2 preceding siblings ...)
  2007-06-30 15:05 ` opichals at seznam dot cz
@ 2007-09-08 23:53 ` bangerth at dealii dot org
  2007-09-17 11:36 ` opichals at seznam dot cz
  4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2007-09-08 23:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bangerth at dealii dot org  2007-09-08 23:52 -------
The code is definitely invalid. The two typedefs declare two types with
external linkage. This is an ODR violation making the code invalid. The
standard doesn't require compilers to produce an error for a very good
reason: it is almost impossible to detect this without support from a linker
that understands all wrinkles and depths of the C++ language.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32549


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/32549] Wrong template instance resolution among multiple object files.
  2007-06-29 17:44 [Bug c++/32549] New: Wrong template instance resolution among multiple object files opichals at seznam dot cz
                   ` (3 preceding siblings ...)
  2007-09-08 23:53 ` bangerth at dealii dot org
@ 2007-09-17 11:36 ` opichals at seznam dot cz
  4 siblings, 0 replies; 6+ messages in thread
From: opichals at seznam dot cz @ 2007-09-17 11:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from opichals at seznam dot cz  2007-09-17 11:35 -------
Yes, I have checked the ODR definition and it is really the fact that the code
violates that. Thank you for your explanations.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32549


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-09-17 11:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-29 17:44 [Bug c++/32549] New: Wrong template instance resolution among multiple object files opichals at seznam dot cz
2007-06-29 17:46 ` [Bug c++/32549] " opichals at seznam dot cz
2007-06-29 19:46 ` pinskia at gcc dot gnu dot org
2007-06-30 15:05 ` opichals at seznam dot cz
2007-09-08 23:53 ` bangerth at dealii dot org
2007-09-17 11:36 ` opichals at seznam dot cz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).