Skip to content

[clang++][frontend] clang++ can't treat & in std::forward<void(int)>(&test<int>); like g++ #122072

@eastB233

Description

@eastB233

source code

#include <utility>

template<typename T>
void test(T a) {}

int main() {
  std::forward<void(int)>(&test<int>);
  return 0;
}

clang fails with

<source>:7:3: error: no matching function for call to 'forward'
    7 |   std::forward<void(int)>(&test<int>);
      |   ^~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/arm64/gcc-12.2.0/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.2.0/../../../../aarch64-unknown-linux-gnu/include/c++/12.2.0/bits/move.h:77:5: note: candidate function template not viable: no overload of 'test' matching 'typename std::remove_reference<void (int)>::type &' (aka 'void (&)(int)') for 1st argument
   77 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
      |     ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/arm64/gcc-12.2.0/aarch64-unknown-linux-gnu/lib/gcc/aarch64-unknown-linux-gnu/12.2.0/../../../../aarch64-unknown-linux-gnu/include/c++/12.2.0/bits/move.h:89:5: note: candidate function template not viable: no overload of 'test' matching 'typename std::remove_reference<void (int)>::type &&' (aka 'void (&&)(int)') for 1st argument
   89 |     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
      |     ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

https://godbolt.org/z/fTGz1PMfs

But gcc is okay
https://godbolt.org/z/d3971PWWM

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueinvalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions