https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91907
Bug ID: 91907 Summary: ['17] Constexpr of member function pointer as template parameter results in inconsistent diagnostics Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kholopov96 at gmail dot com Target Milestone: --- Created attachment 46945 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46945&action=edit Preprocessed sample Consider the following code: ---------------------------------- struct X { template<typename F, F Method, typename ... Args> auto Decorator(Args&&...args) { // std::cout << "decorator\n"; (this->*Method)(&args...); } void bar() { constexpr auto m_ptr = &X::barImpl; Decorator<decltype(m_ptr), m_ptr>(); } void barImpl() { // std::cout << "bar\n"; } }; ---------------------------------- The compilation of this code results in inconsistent diagnostics - it literally states the failure of converting the type to the exactly same type: MVP.cpp:10:39: error: no matching function for call to ‘X::Decorator<void (X::* const)(), m_ptr>()’ 10 | Decorator<decltype(m_ptr), m_ptr>(); | ^ MVP.cpp:3:8: note: candidate: ‘template<class F, F Method, class ... Args> auto X::Decorator(Args&& ...)’ 3 | auto Decorator(Args&&...args) { | ^~~~~~~~~ MVP.cpp:3:8: note: template argument deduction/substitution failed: MVP.cpp:10:39: error: could not convert template argument ‘m_ptr’ from ‘void (X::* const)()’ to ‘void (X::* const)()’ 10 | Decorator<decltype(m_ptr), m_ptr>(); | Other compilers, for. ex. clang++, compile this code without any issues. This might be the copy of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83596, but the diagnostics is even more confusing. Build and tested on Arch Linux, the commit url: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=6ccf1ce78e880c4b5c644d57fc86b991268c333a Full output: $ ~/Build/install/bin/g++ -v -save-temps -c -Wall -Wextra -std=c++17 MVP.cpp Using built-in specs. COLLECT_GCC=/home/igor/Build/install/bin/g++ Target: x86_64-pc-linux-gnu Configured with: ./configure --enable-languages=c++ --prefix=/home/igor/Build/install Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.0.0 20190924 (experimental) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-Wall' '-Wextra' '-std=c++17' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/igor/Build/install/libexec/gcc/x86_64-pc-linux-gnu/10.0.0/cc1plus -E -quiet -v -D_GNU_SOURCE MVP.cpp -mtune=generic -march=x86-64 -std=c++17 -Wall -Wextra -fpch-preprocess -o MVP.ii ignoring nonexistent directory "/home/igor/Build/install/lib/gcc/x86_64-pc-linux-gnu/10.0.0/../../../../x86_64-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /home/igor/Build/install/lib/gcc/x86_64-pc-linux-gnu/10.0.0/../../../../include/c++/10.0.0 /home/igor/Build/install/lib/gcc/x86_64-pc-linux-gnu/10.0.0/../../../../include/c++/10.0.0/x86_64-pc-linux-gnu /home/igor/Build/install/lib/gcc/x86_64-pc-linux-gnu/10.0.0/../../../../include/c++/10.0.0/backward /home/igor/Build/install/lib/gcc/x86_64-pc-linux-gnu/10.0.0/include /usr/local/include /home/igor/Build/install/include /home/igor/Build/install/lib/gcc/x86_64-pc-linux-gnu/10.0.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-Wall' '-Wextra' '-std=c++17' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/igor/Build/install/libexec/gcc/x86_64-pc-linux-gnu/10.0.0/cc1plus -fpreprocessed MVP.ii -quiet -dumpbase MVP.cpp -mtune=generic -march=x86-64 -auxbase MVP -Wall -Wextra -std=c++17 -version -o MVP.s GNU C++17 (GCC) version 10.0.0 20190924 (experimental) (x86_64-pc-linux-gnu) compiled by GNU C version 10.0.0 20190924 (experimental), GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version none GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 GNU C++17 (GCC) version 10.0.0 20190924 (experimental) (x86_64-pc-linux-gnu) compiled by GNU C version 10.0.0 20190924 (experimental), GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version none GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: 527e25ed88abb5131b562d34bbfe759e MVP.cpp: In member function ‘void X::bar()’: MVP.cpp:10:39: error: no matching function for call to ‘X::Decorator<void (X::* const)(), m_ptr>()’ 10 | Decorator<decltype(m_ptr), m_ptr>(); | ^ MVP.cpp:3:8: note: candidate: ‘template<class F, F Method, class ... Args> auto X::Decorator(Args&& ...)’ 3 | auto Decorator(Args&&...args) { | ^~~~~~~~~ MVP.cpp:3:8: note: template argument deduction/substitution failed: MVP.cpp:10:39: error: could not convert template argument ‘m_ptr’ from ‘void (X::* const)()’ to ‘void (X::* const)()’ 10 | Decorator<decltype(m_ptr), m_ptr>(); |