public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
@ 2011-09-28 22:05 ` paolo.carlini at oracle dot com
  2012-03-08 14:29 ` bircoph at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-28 22:05 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|gcc-bugs at gcc dot gnu.org |
         Resolution|                            |WORKSFORME

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-28 21:52:27 UTC ---
In any case, 'W' with current 4.5.x, 4.6.x and mainline.


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
  2011-09-28 22:05 ` [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g paolo.carlini at oracle dot com
@ 2012-03-08 14:29 ` bircoph at gmail dot com
  2012-03-08 14:44 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: bircoph at gmail dot com @ 2012-03-08 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Savchenko <bircoph at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bircoph at gmail dot com

--- Comment #5 from Andrew Savchenko <bircoph at gmail dot com> 2012-03-08 14:28:48 UTC ---
The problem is still here with gcc-4.5.3 if compiled with -O3:

x86_64-pc-linux-gnu-gcc -O -march=core2 -m64 -c TStreamerInfoReadBuffer.cxx -o
TStreamerInfoReadBuffer-1.o
x86_64-pc-linux-gnu-gcc -O2 -march=core2 -m64 -c TStreamerInfoReadBuffer.cxx -o
TStreamerInfoReadBuffer-2.o
x86_64-pc-linux-gnu-gcc -O3 -march=core2 -m64 -c TStreamerInfoReadBuffer.cxx -o
TStreamerInfoReadBuffer-1.o

nm TStreamerInfoReadBuffer-1.o | grep
_ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii
0000000000000000 W _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii
nm TStreamerInfoReadBuffer-2.o | grep
_ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii
0000000000000000 W _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii
nm TStreamerInfoReadBuffer-3.o | grep
_ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii
0000000000007b10 t
_ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii.clone.26

The guilty is -fipa-cp-clone option. Without it symbol is defined well:
x86_64-pc-linux-gnu-gcc -O3 -fno-ipa-cp-clone -march=core2 -m64 -c
TStreamerInfoReadBuffer.cxx -o TStreamerInfoReadBuffer-3-fipa-cp-clone.o
nm TStreamerInfoReadBuffer-3-fipa-cp-clone.o | grep
_ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii
0000000000000000 W _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_iiii


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
  2011-09-28 22:05 ` [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g paolo.carlini at oracle dot com
  2012-03-08 14:29 ` bircoph at gmail dot com
@ 2012-03-08 14:44 ` redi at gcc dot gnu.org
  2012-03-08 15:12 ` bircoph at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-08 14:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-08 14:42:58 UTC ---
It's not a bug though, since you're expecting behaviour which is not guaranteed
and never has been guaranteed.

Why does it matter?  If you have another file where you suppress implicit
instantiation (either by 'extern template' or -fno-implicit-templates) then you
are required to provide an explicit instantiation somewhere in the program.
Assuming an implicit instantiation will happen is an incorrect.


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2012-03-08 14:44 ` redi at gcc dot gnu.org
@ 2012-03-08 15:12 ` bircoph at gmail dot com
  2012-03-08 15:49 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: bircoph at gmail dot com @ 2012-03-08 15:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Savchenko <bircoph at gmail dot com> 2012-03-08 15:11:04 UTC ---
Ok, thanks for clarification. The problem is that I'm not a developer of this
program, I just maintain its package for Gentoo. To make things worse I can't
reproduce the build failure myself on any of my hosts. But users continue to
complain one after another, so this issue needs to be cleared out.

However, I can tell that -fno-implicit-templates was never used during
compilation and I can't find any extern template declarations in that code;
though code is rather sophisticated, I may missed something tricky.


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2012-03-08 15:12 ` bircoph at gmail dot com
@ 2012-03-08 15:49 ` redi at gcc dot gnu.org
  2012-03-08 20:45 ` bircoph at gmail dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-08 15:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-08 15:48:34 UTC ---
(In reply to comment #6)
> Assuming an implicit instantiation will happen is an incorrect.

... is an incorrect /assumption/  :)

(In reply to comment #7)
> Ok, thanks for clarification. The problem is that I'm not a developer of this
> program, I just maintain its package for Gentoo. To make things worse I can't
> reproduce the build failure myself on any of my hosts. But users continue to
> complain one after another, so this issue needs to be cleared out.

Looking at the preprocessed source I see that the member function template
TStreamerInfo::ReadBuffer is declared in TStreamerInfo.h but only defined in
the .cxx file.  If that function (which is public) is called from a different
.cxx file then it will be implicitly instantiated, which isn't possible if the
definition isn't visible.  The member function template definition should be
moved to the header or there should be an explicit instantiation declaration
(i.e. 'extern template' declaration) in the header and an explicit
instantiation definition in the .cxx file.


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2012-03-08 15:49 ` redi at gcc dot gnu.org
@ 2012-03-08 20:45 ` bircoph at gmail dot com
  2012-03-08 21:06 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: bircoph at gmail dot com @ 2012-03-08 20:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Andrew Savchenko <bircoph at gmail dot com> 2012-03-08 20:44:24 UTC ---
(In reply to comment #8)
> Looking at the preprocessed source I see that the member function template
> TStreamerInfo::ReadBuffer is declared in TStreamerInfo.h but only defined in
> the .cxx file.  If that function (which is public) is called from a different
> .cxx file then it will be implicitly instantiated, which isn't possible if the
> definition isn't visible.  The member function template definition should be
> moved to the header or there should be an explicit instantiation declaration
> (i.e. 'extern template' declaration) in the header and an explicit
> instantiation definition in the .cxx file.

Hmm, I can't understand this (though I don't know all the details of the C++
standard). If I'm writing class MyClass with public method Read, this is
absolutely normal to declare Read function in the class declaration in the
MyClass.h header and define it in the MyClass.cpp. Templates are supposed to
work just as a normal functions, with the difference that code is written once,
instead of writing a bunch of overloaded functions.

If all templates must be defined in the single header, this would make an
thousands lines of code header file. And explicit template will require
compile-tyme type specification, which is impossible due to RTTI being used.


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2012-03-08 20:45 ` bircoph at gmail dot com
@ 2012-03-08 21:06 ` redi at gcc dot gnu.org
  2012-03-08 21:17 ` Fons.Rademakers at cern dot ch
  2012-03-08 23:27 ` bircoph at gmail dot com
  8 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-08 21:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-08 21:05:02 UTC ---
(In reply to comment #9)
> Hmm, I can't understand this (though I don't know all the details of the C++
> standard). If I'm writing class MyClass with public method Read, this is
> absolutely normal to declare Read function in the class declaration in the
> MyClass.h header and define it in the MyClass.cpp. Templates are supposed to
> work just as a normal functions, with the difference that code is written once,
> instead of writing a bunch of overloaded functions.

No, they aren't just like normal functions.

Maybe you should read
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12

> If all templates must be defined in the single header, this would make an
> thousands lines of code header file.

Who said they have to be in a /single/ header?

Have you ever looked at the implementation of e.g. <string> or <vector>?
They're entirely defined in headers.  There's a reason for that.

> And explicit template will require
> compile-tyme type specification, which is impossible due to RTTI being used.

I don't know what RTTI has to do with anything and don't know what you mean.

The explicit instantiation you need is the one that you get a linker error for
i.e.
extern template
  int TStreamerInfo::ReadBuffer(TBuffer&, char** const&, int, int, int, int);


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2012-03-08 21:06 ` redi at gcc dot gnu.org
@ 2012-03-08 21:17 ` Fons.Rademakers at cern dot ch
  2012-03-08 23:27 ` bircoph at gmail dot com
  8 siblings, 0 replies; 13+ messages in thread
From: Fons.Rademakers at cern dot ch @ 2012-03-08 21:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Fons Rademakers <Fons.Rademakers at cern dot ch> 2012-03-08 21:16:57 UTC ---
Hi Andrew,

  the source code now (r43307) uses explicit instantiation and should work on
Gentoo with all compiler versions and optimization levels.

If you want older versions to work remove the conditionals at the bottom of
io/io/Module.mk.

Issue can be closed.


Cheers, Fons.


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
       [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2012-03-08 21:17 ` Fons.Rademakers at cern dot ch
@ 2012-03-08 23:27 ` bircoph at gmail dot com
  8 siblings, 0 replies; 13+ messages in thread
From: bircoph at gmail dot com @ 2012-03-08 23:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Andrew Savchenko <bircoph at gmail dot com> 2012-03-08 23:27:15 UTC ---
Hello,

(In reply to comment #10)
> No, they aren't just like normal functions.
> 
> Maybe you should read
> http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12

Thank you again, I misunderstood concept behind template implementation.

(In reply to comment #11)
>   the source code now (r43307) uses explicit instantiation and should work on
> Gentoo with all compiler versions and optimization levels.
> 
> If you want older versions to work remove the conditionals at the bottom of
> io/io/Module.mk.

Thanks for fixing this problem. I'll apply the solution to our packages soon.


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
  2009-05-07  9:59 [Bug c++/40056] New: " Fons dot Rademakers at cern dot ch
                   ` (2 preceding siblings ...)
  2009-05-07 12:25 ` pinskia at gcc dot gnu dot org
@ 2009-05-07 13:55 ` Fons dot Rademakers at cern dot ch
  3 siblings, 0 replies; 13+ messages in thread
From: Fons dot Rademakers at cern dot ch @ 2009-05-07 13:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from Fons dot Rademakers at cern dot ch  2009-05-07 13:55 -------
Explicit template instantiation also works for us in this case. However, would
be nice to see this regression fixed. No blocker anymore.


-- 


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


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
  2009-05-07  9:59 [Bug c++/40056] New: " Fons dot Rademakers at cern dot ch
  2009-05-07 10:02 ` [Bug c++/40056] " Fons dot Rademakers at cern dot ch
  2009-05-07 12:24 ` pinskia at gcc dot gnu dot org
@ 2009-05-07 12:25 ` pinskia at gcc dot gnu dot org
  2009-05-07 13:55 ` Fons dot Rademakers at cern dot ch
  3 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-07 12:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-05-07 12:25 -------
The implicit instantiation of function templates could be inlined at which
point, it does not need to be emitted.


-- 


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


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
  2009-05-07  9:59 [Bug c++/40056] New: " Fons dot Rademakers at cern dot ch
  2009-05-07 10:02 ` [Bug c++/40056] " Fons dot Rademakers at cern dot ch
@ 2009-05-07 12:24 ` pinskia at gcc dot gnu dot org
  2009-05-07 12:25 ` pinskia at gcc dot gnu dot org
  2009-05-07 13:55 ` Fons dot Rademakers at cern dot ch
  3 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-05-07 12:24 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
           Severity|blocker                     |normal


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


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

* [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...
  2009-05-07  9:59 [Bug c++/40056] New: " Fons dot Rademakers at cern dot ch
@ 2009-05-07 10:02 ` Fons dot Rademakers at cern dot ch
  2009-05-07 12:24 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Fons dot Rademakers at cern dot ch @ 2009-05-07 10:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from Fons dot Rademakers at cern dot ch  2009-05-07 10:01 -------
Created an attachment (id=17817)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17817&action=view)
Source file (-E output) demonstrating the reported issue.

Btw, this bug shows up on MacOS X 10.5.6, Linux RHEL 5 and Ubuntu 9, i.e. it is
platform independent.


-- 


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


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

end of thread, other threads:[~2012-03-08 23:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-40056-4@http.gcc.gnu.org/bugzilla/>
2011-09-28 22:05 ` [Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g paolo.carlini at oracle dot com
2012-03-08 14:29 ` bircoph at gmail dot com
2012-03-08 14:44 ` redi at gcc dot gnu.org
2012-03-08 15:12 ` bircoph at gmail dot com
2012-03-08 15:49 ` redi at gcc dot gnu.org
2012-03-08 20:45 ` bircoph at gmail dot com
2012-03-08 21:06 ` redi at gcc dot gnu.org
2012-03-08 21:17 ` Fons.Rademakers at cern dot ch
2012-03-08 23:27 ` bircoph at gmail dot com
2009-05-07  9:59 [Bug c++/40056] New: " Fons dot Rademakers at cern dot ch
2009-05-07 10:02 ` [Bug c++/40056] " Fons dot Rademakers at cern dot ch
2009-05-07 12:24 ` pinskia at gcc dot gnu dot org
2009-05-07 12:25 ` pinskia at gcc dot gnu dot org
2009-05-07 13:55 ` Fons dot Rademakers at cern dot ch

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).