2012-11-15 3 views
3
내가

컴파일 오류

#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 
} 

이 코드 네임 스페이스없이 유형의 고정 매개 변수 기능 또는 L-값 심판에 작동 아래 같은 몇 가지 매개 변수 포장 도우미 코드를 작성하기 위해 노력하고있어

,하지만 내 컴파일러 rejects는 일부 네임 스페이스에서 r-value ref 매개 변수를 사용하려고 시도합니다. 내가 VC11의 CTP 버전을 사용하고, 에러 메시지가 다소 이해할 수

1>d:\work\toy\vs2012test\vs2012test\source.cpp(39): error C2065: 'basic_string<char,std::char_traits<char>,std::allocator<char> >' : undeclared identifier 
1>   d:\work\toy\vs2012test\vs2012test\source.cpp(52) : see reference to function template instantiation 'void wrapper_variadic<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>(std::basic_string<char,std::char_traits<char>,std::allocator<char>> &&)' being compiled 
1>d:\work\toy\vs2012test\vs2012test\source.cpp(39): error C2923: 'std::decay' : 'basic_string<char,std::char_traits<char>,std::allocator<char> >' is not a valid template type argument for parameter '_Ty' 
1>d:\work\toy\vs2012test\vs2012test\source.cpp(39): error C2955: 'std::decay' : use of class template requires template argument list 
1>   c:\program files (x86)\microsoft visual studio 11.0\vc\include\type_traits(1620) : see declaration of 'std::decay' 
1>d:\work\toy\vs2012test\vs2012test\source.cpp(39): error C2440: '<function-style-cast>' : cannot convert from 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' to 'arg_wrapper<_If<std::is_array<remove_reference<_Ty>::type>::value,remove_extent<remove_reference<_Ty>::type>::type*,_If<std::is_function<remove_reference<_Ty>::type>::value,add_pointer<remove_reference<_Ty>::type>::type,remove_cv<remove_reference<_Ty>::type>::type>::type>::type>' 
1>   Source or target has incomplete type 
1>d:\work\toy\vs2012test\vs2012test\source.cpp(39): error C2440: '<function-style-cast>' : cannot convert from 'ns::test' to 'arg_wrapper<test>' 
1>   No constructor could take the source type, or constructor overload resolution was ambiguous 
1>   d:\work\toy\vs2012test\vs2012test\source.cpp(54) : see reference to function template instantiation 'void wrapper_variadic<ns::test>(ns::test &&)' being compiled 

그것은 컴파일러의 버그처럼 보인다 (아래 참조),하지만 난 그것에 대해 확신이 없습니다. 이 버그인가? 그렇지 않다면 문제를 해결하기 위해 무엇을해야합니까?

+1

확실히 오류로 보입니다. Bravo for the test case;) –

+0

VC에서 최종적으로 가변적 인 템플릿을 구현 했습니까? – mfontanini

+1

CTP 변종은 지옥과 같은 버그입니다. 여러 가지 방법으로 가변성을 사용하는 GCC/Clang의 코드를 포트에 넣으려고했는데 그날 밤 11 개의 가변 버그를 제출했습니다 ('decltype'의 경우 +3). :) – Xeo

답변

1

g ++ 4.7.2 및 clang ++ 3.2로 잘 컴파일됩니다. 아마도 컴파일러 버그 일 것입니다. 그것은 vc11 확장 팩을 제대로 구현하지 않는 것 같습니다.