Variadic template bug in vs2012 november CTP - by summerlight

Status : 

 


3
0
Sign in
to vote
ID 771311 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 11/15/2012 4:15:23 PM
Access Restriction Public

Description

CTP compiler fails to compile legimate variadic template code. See below code.

#include <type_traits>
#include <string>

struct test{};

namespace ns {
    struct test{};
}

template<typename T>
struct arg_wrapper;

template<>
struct arg_wrapper<test>
{
    arg_wrapper(test&) {}
};

template<>
struct arg_wrapper<ns::test>
{
    arg_wrapper(ns::test&) {}
};

template<>
struct arg_wrapper<std::string>
{
    arg_wrapper(const std::string& value) {}
};

template<typename... Args>
void callee(const Args&... args)
{
}

template<typename... Args>
void wrapper_variadic(Args&&... args)
{
    callee(arg_wrapper<typename std::decay<Args>::type>(args)...);
}

template<typename Args>
void wrapper_fixed(Args&& args)
{
    callee(arg_wrapper<typename std::decay<Args>::type>(args));
}

int main()
{
    std::string a("test");
    wrapper_variadic(a); // works well
    wrapper_variadic(std::string("test")); // compile error
    wrapper_variadic(test()); // works well
    wrapper_variadic(ns::test()); // compile error
    wrapper_fixed(std::string("test")); // works well
    wrapper_fixed(test()); // works well
    wrapper_fixed(ns::test()); // works well
}

In detail, a variadic parameter with type in some namespace is passed into variadic template function by r-value reference. (ex. std::string&&) Then the compiler truncates its namespace(ex. std::basic_string<blah> -> basic_string<blah>) and tries to find its declaration, which issues compile error.
Sign in to post a comment.
Posted by Deon [MSFT] on 4/29/2014 at 12:31 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Xiang [MSFT] on 12/28/2012 at 12:27 PM
Hi:
    Thanks for reporting the issue.
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by Ad aCTa on 11/19/2012 at 12:19 PM
Following code is more minimalistic with same problem:

#include <string>

template <typename ReturnType, typename ...Args>
ReturnType call(ReturnType(*param)(Args&&...), Args&&... args) {
    using namespace std;                                     // <--- only compiles if std::forward is specified
    return param(std::forward<Args>(args)...);
}

int conv(std::string&& test) {
    return 0;
}

int main() {
    call(conv, std::string("5"));
}
Posted by Helen [MSFT] on 11/15/2012 at 6:18 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 Macy [MSFT] on 11/15/2012 at 4:52 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)