Search

implicit instantiation of virtual template method causes confusing warning by Krishty

Closed
as Deferred Help for as Deferred

5
0
Sign in
to vote
Type: Bug
ID: 778490
Opened: 2/4/2013 11:29:49 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
It looks like calling the virtual method of a template causes all of its virtual methods being instantiated. According to the C++ standard, this is alright.

However, if one of the methods was defined outside of the class, warning C4505 (unreferenced local function has been removed) is raised. I suppose this is due to Visual C++ omitting the needless virtual functions it instantiated right before.

The warning is pretty confusing and should either be changed or disabled.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

// compile with /W4

template <typename T> struct HasVirtuals {
    virtual void a();
    virtual void b();
};

template <typename T> void HasVirtuals<T>::a() { }

template <typename T> void HasVirtuals<T>::b() { }

void foo(HasVirtuals<int> * ptr) {
    ptr->b(); // causes C4505
}

Product Language

English

Operating System

Windows 7 SP1

Operating System Language

English

Actual results

main.cpp(3): warning C4505: 'HasVirtuals<T>::a' : unreferenced local function has been removed
1>         with
1>         [
1>             T=int
1>         ]

Expected results

Silence, or Visual C++ giving the hint that an explicit specialization might be desired here. Also, the warning is raised at a completely different location, sometimes deep in the STL headers. It is nearly impossible to find the cause in a huge code base.

Since the warning never appears for virtual method definitions in the class body, I assume this code path had just been overlooked.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 2/4/2013 at 9:54 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 2/4/2013 at 11:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.