Search

decltype expressions involving polymorphic callable entities fails in VC++11 Beta but works in VC++10 by sharp_kid

Closed
as Fixed Help for as Fixed

2
0
Sign in
to vote
Type: Bug
ID: 732063
Opened: 3/19/2012 3:30:39 PM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
Writing decltype expressions involving polymorphic callable entities (template function call operator overload) in VC++11 Beta causes the compile-error:

"error C2893: Failed to specialize function template ''unknown-type'..."

But the same decltype expressions compiles and works fine in VC++2010 (and GCC 4.6.2). Code which can reproduce the problem:

template < typename Fn >
struct Foo
{
    Fn fn;

    template < typename Tp >
    auto operator()(const Tp& x) const -> decltype(fn(x)) { return fn(x); }
};

struct Bar
{
    template < typename Tp >
    int operator()(const Tp& x) const { return 0; }
};

template < typename Fn >
void foobar(Fn f)
{
    typedef decltype(f(0)) result_type;
}

int main()
{
    foobar(Foo<Bar>());
    return 0;
}
Details (expand)

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

Visual Studio 11 Beta

Steps to reproduce

Compile the following code in VC++11 Beta:

template < typename Fn >
struct Foo
{
    Fn fn;

    template < typename Tp >
    auto operator()(const Tp& x) const -> decltype(fn(x)) { return fn(x); }
};

struct Bar
{
    template < typename Tp >
    int operator()(const Tp& x) const { return 0; }
};

template < typename Fn >
void foobar(Fn f)
{
    typedef decltype(f(0)) result_type;
}

int main()
{
    foobar(Foo<Bar>());
    return 0;
}

Product Language

English

Operating System

Windows 8

Operating System Language

English

Actual results

1>------ Build started: Project: ConsoleApplication3, Configuration: Debug Win32 ------
1>Build started 19/03/2012 22:28:36.
1>ClCompile:
1> ConsoleApplication3.cpp
1>c:\users\ca\documents\visual studio 11\projects\consoleapplication3\consoleapplication3\consoleapplication3.cpp(24): error C2893: Failed to specialize function template ''unknown-type' Foo<Fn>::operator ()(const Tp &) const'
1>         with
1>         [
1>             Fn=Bar
1>         ]
1>         With the following template arguments:
1>         'int'
1>         c:\users\ca\documents\visual studio 11\projects\consoleapplication3\consoleapplication3\consoleapplication3.cpp(29) : see reference to function template instantiation 'void foobar<Foo<Fn>>(Foo<Fn>)' being compiled
1>         with
1>         [
1>             Fn=Bar
1>         ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.07
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Expected results

Should compile without error and deduce the return type of the callable expression.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 3/23/2012 at 2:28 PM
Hi: a fix for this issue has been applied to the compiler sources and it should show up in the next release of Visual C++.

Thanks
Jonathan Caves
Visual C++ Compiler Team
Posted by MS-Moderator07 [Feedback Moderator] on 3/19/2012 at 8:02 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 MS-Moderator01 on 3/19/2012 at 3:45 PM
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.