Hi, the following testcase fails to compile with g++ 4.9.1 and 5.0.0 (20140925). -- test.cc template <typename T1, typename S1> struct B { }; template <typename T1> struct A { private: template <typename T2, typename S2> static B<T2, S2> bar(); public: template <typename S2> auto foo1() -> decltype(bar<T1, S2>()); }; // (*) template<> template<> auto A<int>::foo1<float>() -> B<int, float>; -- end of test.cc $ g++ --version g++ (GCC) 5.0.0 20140925 (experimental) $ g++ -c -std=c++11 -c test.cc test.cc:18:6: error: template-id ‘foo1<float>’ for ‘B<int, float> A<int>::foo1()’ does not match any template declaration auto A<int>::foo1<float>() -> B<int, float>; ^ but making 'A<T1>::bar' public or using '-fno-access-control' g++ accepts the code OK. Explicitly using a manually substituted decltype gives a clue of what is going on -- test.cc // Declarations of B and A above // (*) template<> template<> auto A<int>::foo1<float>() -> decltype(A<int>::bar<int, float>()); -- end of test.cc $ g++ -c -std=c++11 -c test.cc test.cc:22:6: error: template-id ‘foo1<float>’ for ‘B<int, float> A<int>::foo1()’ does not match any template declaration auto A<int>::foo1<float>() -> decltype(A<int>::bar<int, float>()); ^ test.cc:9:26: error: ‘static B<T2, S2> A<T1>::bar() [with T2 = int; S2 = float; T1 = int]’ is private static B<T2, S2> bar(); ^ test.cc:22:64: error: within this context auto A<int>::foo1<float>() -> decltype(A<int>::bar<int, float>()); Both clang-3.5 and icc 14.0.2 accept this code. Kind regards,
Created attachment 33578 [details] Testcase
This seems to be fixed for GCC 12+ by r12-4453-g79802c5dcc043a. Before closing the PR we should add this testcase to the testsuite.
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>: https://gcc.gnu.org/g:475b7f44c640c03f968d66dae389ea6165b4b5c2 commit r14-6422-g475b7f44c640c03f968d66dae389ea6165b4b5c2 Author: Patrick Palka <ppalka@redhat.com> Date: Mon Dec 11 11:59:33 2023 -0500 c++: add fixed testcase [PR63378] We accept this testcase since r12-4453-g79802c5dcc043a. PR c++/63378 gcc/testsuite/ChangeLog: * g++.dg/template/fnspec3.C: New test.
Fixed.