关于template argument deduction with variadic template template的编译器一致性问题咨询
Hey there, I've run into a confusing situation with C++ template argument deduction involving variadic template templates, and different compilers are giving conflicting results. Let me break it down:
I have three similar structs with static template member functions. All three functions take a template template parameter that expects a type, a non-type auto parameter, and then a variadic pack of types. When I try to call these functions with an instance of a matching template, the results vary across compilers:
SNonTemplate::foo(TestTemplate<S, 0>()): Accepted by all compilersSTemplate<S>::foo(TestTemplate<S, 0>()): Accepted by all compilersSVariadicTemplate<S>::foo(TestTemplate<S, 0>()): Accepted by GCC, but rejected by Clang and MSVC
Here's the complete code example:
#include <utility> struct S {}; struct SNonTemplate { template<template<typename, auto, typename...> typename Template, typename T1, auto V, typename... T> static void foo(Template<T1, V, T...>) {} }; template<typename> struct STemplate { template<template<typename, auto, typename...> typename Template, typename T1, auto V, typename... T> static void foo(Template<T1, V, T...>) {} }; template<typename> struct SVariadicTemplate { template<template<typename, auto, typename...> typename Template, typename T1, auto V, typename... T> static void foo(Template<T1, V, T...>) {} }; template<typename, auto, typename...> struct TestTemplate {}; int main() { SNonTemplate::foo(TestTemplate<S, 0>()); STemplate<S>::foo(TestTemplate<S, 0>()); SVariadicTemplate<S>::foo(TestTemplate<S, 0>()); }
The problem is that Clang and MSVC fail to deduce the template arguments for the third call, claiming the argument doesn't match the parameter, while GCC handles it without issues. I'm trying to figure out which compiler is adhering to the C++ standard correctly here—Is this a bug in Clang/MSVC, or is GCC being overly permissive?
内容来源于stack exchange

