<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62388>62388</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Compile error casting from overloaded static member function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gknowles
</td>
</tr>
</table>
<pre>
I believe that gcc & msvc are correct here, and o1 should be allowed. At best the error about creating a non-const pointer is misleading as it seems to be triggered by having an overload set.
Thanks!
~~~ C++
struct A {
static void simple(int val) { }
static void overloaded(int val) { }
static void overloaded(long val) { }
};
void test() {
A f;
auto s1 = static_cast<void(*)(int)>(f.simple); // ok
auto s2 = static_cast<void(*)(int)>(A::simple); // ok
auto o1 = static_cast<void(*)(int)>(f.overloaded); // msvc & gcc ok, clang error
auto o2 = static_cast<void(*)(int)>(A::overloaded); // ok
}
~~~
~~~
clang version 16.0.0 (https://github.com/llvm/llvm-project.git 08d094a0e457360ad8b94b017d2dc277e697ca76)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-16.0.0/bin
Found candidate GCC installation: /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0
Selected GCC installation: /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
(in-process)
"/opt/compiler-explorer/clang-16.0.0/bin/clang-16" -cc1 -triple x86_64-unknown-linux-gnu -S -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-16.0.0/lib/clang/16 -internal-isystem /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0 -internal-isystem /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/backward -internal-isystem /opt/compiler-explorer/clang-16.0.0/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/app -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -mllvm --x86-asm-syntax=intel -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /app/output.s -x c++ <source>
clang -cc1 version 16.0.0 based upon LLVM 16.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/x86_64-linux-gnu
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/backward
/opt/compiler-explorer/clang-16.0.0/lib/clang/16/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
<source>:12:41: error: cannot create a non-constant pointer to member function
auto o1 = static_cast<void(*)(int)>(f.overloaded);
^~~~~~~~~~~~
1 error generated.
Compiler returned: 1
~~~
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWEtv4zgS_jX0pUBBIv08-OC249kGZi7bi9ljQJElmRuKFEjKcS757QtKcuxNO0lnMOjtbsORSx_rxaqPDxGCri3imsy-kNluIrp4cH5dP1j3aDBMSqee1l-hRKPxiBAPIkItJRA2hyYcJQiPIJ33KCMc0CNhWxBWgSsgHFxnFJQIwhj3iCqDTYQSQ4R4QEDvnQdRui6C9CiitjUIsM5S6WyI0DptI3rQARodDArVIwLoCAGxCRBd0h69rmv0qKB8goM49igL7ojeOKEgYMxIviP5Zvj-10HYh0BYcS18fn6GLWFf0qcXhOg7GWEDZDFKAABCFFFLODqtIOimNUjYUtsIR2EIWyUwkMXu9oCzR6j-6iDjbH1zVHrgX64D6gdHDJGw5Qi_GNhA9QIH0UUHoQDCd6PleylCJHybdPTDN4StBp_TA78jbFll5_hXhH8BwvaE7cE9XIwMetkn9W4IT58fUu4-7_R1Oq9198WcqjpVt3tIZSyNsPVQpteZcn8xorcsn6N6mcvn5-dXlTk8DP4c0QftLBTzLM9yIGx5iLENyUavr9bx0JWZdA1he2OO5z-09e4_KGNW6wj5UuWrqchxOlvweS7UslxNy7xYKKYkWyxwvlpIsZgnT4eeEb7GSPgGTsv5_XxKO5sowlKjbXeite3OveVRKGicQpPQrQv6NLz6akMUxqDaaZ9eEbZ3bSRsL13TaoOe4qk1zqNPshQrHWIkbF9qOyjZu84qkMIqrURE-G27BT0oFlE7-6HiWkpasIz1ao0uBxFh-zGuSzxsP-J6w9_QoIyofp7F7UuQTWeiTiP5BrLUt9O8mU_fQ3E2wjh7D3Z6wZ3OwJc43zMKfYWnipIYwkuRAGHss7N6ERLGgEpZAI1etwbfrDSg34AqHURpkFYeEag0KDwVIdISK-eRlkI-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