Bug 42340 - templated member func vanish from assembler code when -O2 is used
Summary: templated member func vanish from assembler code when -O2 is used
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-09 10:40 UTC by Christoph Jaeschke
Modified: 2009-12-09 11:34 UTC (History)
1 user (show)

See Also:
Host: i486-linux-gnu
Target: i486-linux-gnu
Build: i486-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Jaeschke 2009-12-09 10:40:58 UTC
Using the below code snipped (bug.C), and compiling it using:

  gcc -Wall -O2 -save-temps -c -o bug.o bug.C

causes _ZN1B1fIiEEvPT_ to disappear from the .s-file, and later on breaking the link. Using -O1 works fine.

---- bug.C ----

struct B {
    template <class T> void f(T * t);
    void dummyInst();
};

template <class T> void
B::f(T * t)
{
}

void
B::dummyInst() {
    f((int*)0);
}
Comment 1 Paolo Carlini 2009-12-09 11:08:47 UTC
I'm seeing this happening in 4.3.x too, isn't new in 4.4.x.

Now, I'm not sure to understand which is the problem: indeed, it disappears, but it's also true that nothing calls it. I would ask you to provide a short testcase which doesn't link anymore and was fine before (4.2.x?). Thanks.
Comment 2 Jonathan Wakely 2009-12-09 11:29:25 UTC
If another translation unit is relying on finding an instantiation in bug.o then you should use an explicit instantiation to ensure it is present, or the other translation unit should include the definition of B::f
Comment 3 Paolo Carlini 2009-12-09 11:34:16 UTC
This is expected, any optimizing compiler (e.g., ICC behaves the same as GCC) will get rid of that implicit instantiation, while inlining. Really, this is not going to change.