2017-12-28 33 views
0

자동 비 유형 매개 변수 (C++ 17)를 사용하려고합니다. 'Sample1 :: type'은 'integral_constraint < int, 0 >'이어야하지만 'Sample0 :: type'과 동일 할 것으로 예상됩니다.g ++ 7.2.0이 자동 비 유형 매개 변수 공제에 실패했습니다.

g ++ 버그 또는 기능에 대한 오해가 있습니까? 우분투 17.10에서 g ++ (Ubuntu 7.2.0-8ubuntu3) 7.2.0을 사용합니다.

-- auto_param.cxx -- 
#include <iostream> 
#include <type_traits> 
#include <boost/type_index.hpp> 

template <auto V> 
struct Value { 
    using type = std::integral_constant<decltype(V), V>; 
}; 

template <typename T> 
auto demangle() { 
    return boost::typeindex::type_id_with_cvr<T>().pretty_name(); 
} 

void zero_as_uint() { 
    using Sample0 = Value<0u>; 
    std::cout << __func__ << ": " << demangle<Sample0::type>() << std::endl; 
} 

void zero_as_int() { 
    using Sample1 = Value<0>; 
    std::cout << __func__ << ": " << demangle<Sample1::type>() << std::endl; 
} 

int main(int, char**) { 
    zero_as_uint(); 
    zero_as_int(); 
    return 0; 
} 
----------------------------- 
$ g++ -Wall -std=c++17 auto_param.cxx && ./a.out 
zero_as_uint: std::integral_constant<unsigned int, 0u> 
zero_as_int: std::integral_constant<unsigned int, 0u> 

예상대로 예상대로 clang ++가 발견되었습니다.

$ clang++-5.0 -Wall -std=c++17 auto_param.cxx && ./a.out 
zero_as_uint: std::integral_constant<unsigned int, 0u> 
zero_as_int: std::integral_constant<int, 0> 
+0

템플릿 은 T가 유형 또는 비 유형 중 하나가 될 수 있다는 새로운 방식입니까? 나는 거기에 "클래스"또는 "typename"을 보는데 익숙하다. – Zebrafish

+0

@Zebrafish 아니면 변수 일 것임에 틀림 없다. 아마도 여러분은 아마도'int'를 보았을 것입니다, 맞습니까? 글쎄요, 여기 똑같은 타입입니다. 타입이 추론됩니다. – Rakete1111

+0

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79092 – cpplearner

답변

2

그건 bug in gcc입니다. 또 환원 예는 다음과 같다 : 서로 다른 템플릿 인스턴스화 참조로

#include <type_traits> 

template <auto V> 
struct Value { 
    using type = std::integral_constant<decltype(V), V>; 
}; 

static_assert(!std::is_same_v<Value<0u>::type, Value<0>::type>); 

이러한 두 가지 가능성이 동일하지 않을 수있다. gcc has always had the bug처럼 보이지만 최신 트렁크에서 수정되었습니다.