4
votes

I try to write a code with c++17 auto non-type template parameter pack for class data member pointer, but the following code clang will compile and gcc will not, you can see godbolt for error message, can somebody tell me which one should I believe since I can't figure out why gcc reject this.

Thanks for you help.

template <
    typename B,
    template <auto B::*...> typename Wrapper, 
    auto B::*... Args
>
void f(Wrapper<Args...>) {}

template <auto... Args> struct Wrapper {};
struct A { int i; float f; };

// gcc error: unable to deduce 'auto B::*' from '&A::i'
f(Wrapper<&A::i, &A::f>{});

I know that if change <auto B::*...> to <auto...> then both can compile, but I want know why gcc couldn't deduce correct type since the following non-auto template parameter get same situation: gcc can't compile and clang can:

template <
    typename B,
    typename... MT,
    template <MT B::*...> class Wrapper, 
    MT B::*... Args
>
void f(Wrapper<Args...>) {}
1

1 Answers

2
votes

Try with

template <
    template <auto ...> typename Wrapper, 
    auto ... Args
>
void f(Wrapper<Args...>) {}

auto is an alternative for B::*; so you should use auto or B::*, not both.