https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63378
Bug ID: 63378 Summary: decltype and access control issues Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: roger.ferrer at bsc dot es 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,