public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51936] New: template function not instantiated
@ 2012-01-21 18:14 blaffablaffa at gmail dot com
  2012-01-21 20:32 ` [Bug c++/51936] " redi at gcc dot gnu.org
  2012-01-28  2:11 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: blaffablaffa at gmail dot com @ 2012-01-21 18:14 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51936
           Summary: template function not instantiated
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: blaffablaffa@gmail.com


Created attachment 26405
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26405
test case

It appears that in some circumstances g++ fails to instantiate a template
function, and so end up in link time errors.

Consider the code in attachment. If compiled with:

g++ -Wall -std=c++0x testcase.cpp

the result is:

testcase.cpp:(.text+0x13): undefined reference to `int asd<int, 0>(int*)'
collect2: ld returned 1 exit status

whereas if compiled with:

g++ -Wall -std=c++0x -DWORKAROUND testcase.cpp

it does warn for the unused variable 'inted', but compiles and run correctly.


It looks like that getting the pointer of a template function and immediately
cast it to something else "weakens" the usage of the template, so that g++
doesn't instantiate it.


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

* [Bug c++/51936] template function not instantiated
  2012-01-21 18:14 [Bug c++/51936] New: template function not instantiated blaffablaffa at gmail dot com
@ 2012-01-21 20:32 ` redi at gcc dot gnu.org
  2012-01-28  2:11 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2012-01-21 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-21 20:23:27 UTC ---
The standard says in [expr.reinterpret.cast]
"A function pointer can be explicitly converted to a function pointer of a
different type. The effect of calling a function through a pointer to a
function type (8.3.5) that is not the same as the type used in the definition
of the function is undefined."

So I think the program has undefined behaviour.  Because you never call
asd<int,0> as part of a valid expression it doesn't need to be instantiated.


Clang++ fails in the same way as G++ 4.6, but it works with G++ 4.7


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

* [Bug c++/51936] template function not instantiated
  2012-01-21 18:14 [Bug c++/51936] New: template function not instantiated blaffablaffa at gmail dot com
  2012-01-21 20:32 ` [Bug c++/51936] " redi at gcc dot gnu.org
@ 2012-01-28  2:11 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-01-28  2:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WORKSFORME

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-01-27 23:36:32 UTC ---
Thus, I think we can safely close this.


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-21 18:14 [Bug c++/51936] New: template function not instantiated blaffablaffa at gmail dot com
2012-01-21 20:32 ` [Bug c++/51936] " redi at gcc dot gnu.org
2012-01-28  2:11 ` paolo.carlini at oracle dot com

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