llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.3k stars 12.11k forks source link

[clang] Invocation of NTTP pointer to explicit this member function is rejected #106660

Open vasama opened 2 months ago

vasama commented 2 months ago

https://godbolt.org/z/75vxezzoW

struct s
{
        void f(this s&);
};

template<auto F>
constexpr void f(s& x)
{
        return F(x);
}

int main()
{
        &f<&s::f>;
}

Output:

C:\Users\vasama\sandbox λ clang --version
clang version 18.1.8
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
C:\Users\vasama\sandbox λ clang -std=c++23 test.cpp
test.cpp:9:9: error: must explicitly qualify name of member function when taking its address
    9 |         return F(x);
      |                ^
      |                s::
test.cpp:14:3: note: in instantiation of function template specialization 'f<&s::f>' requested here
   14 |         &f<&s::f>;
      |          ^
test.cpp:14:2: warning: expression result unused [-Wunused-value]
   14 |         &f<&s::f>;
      |         ^~~~~~~~~
1 warning and 1 error generated.
llvmbot commented 2 months ago

@llvm/issue-subscribers-clang-frontend

Author: Lauri Vasama (vasama)

https://godbolt.org/z/75vxezzoW ```CPP struct s { void f(this s&); }; template<auto F> constexpr void f(s& x) { return F(x); } int main() { &f<&s::f>; } ``` Output: ```console C:\Users\vasama\sandbox λ clang --version clang version 18.1.8 Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin C:\Users\vasama\sandbox λ clang -std=c++23 test.cpp test.cpp:9:9: error: must explicitly qualify name of member function when taking its address 9 | return F(x); | ^ | s:: test.cpp:14:3: note: in instantiation of function template specialization 'f<&s::f>' requested here 14 | &f<&s::f>; | ^ test.cpp:14:2: warning: expression result unused [-Wunused-value] 14 | &f<&s::f>; | ^~~~~~~~~ 1 warning and 1 error generated. ```