https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107623

            Bug ID: 107623
           Summary: Using a parameter pack twice results in ambiguous
                    overloaded function.
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlaros at fixedpoint dot nl
  Target Milestone: ---

The following example does not compile:

    template <class R, class... Args>
    void test(R (*)(Args...), Args...) {}

    template <class... Args>
    void test(void (*)(Args...), Args...) {}

    int main() {
      void (*f)(int) {};
      test(f, 1);
    }

Example:

    $ g++ -Wall -Wextra -pedantic x.cc
    x.cc: In function ‘int main()’:
    x.cc:11:7: error: call of overloaded ‘test(void (*&)(int), int)’ is
ambiguous
       11 |   test(f, 1);
          |   ~~~~^~~~~~
    x.cc:2:6: note: candidate: ‘void test(R (*)(Args ...), Args ...) [with R =
void; Args = {int}]’
        2 | void test(R (*)(Args...), Args...) {}
          |      ^~~~
    x.cc:5:6: note: candidate: ‘void test(void (*)(Args ...), Args ...) [with
Args = {int}]’
        5 | void test(void (*)(Args...), Args...) {}
          |      ^~~~

This might be a bug because the following variants on the same theme do compile
without errors or warnings:

    template <class R, class T>
    void test(R (*)(T), T) {}

    template <class T>
    void test(void (*)(T), T) {}

And:

    template <class R, class... FArgs, class... Args>
    void test(R (*)(FArgs...), Args...) {}

    template <class... FArgs, class... Args>
    void test(void (*)(FArgs...), Args...) {}

The first example does compile when using clang (version 14.0.6).

Reply via email to