Bug 63378 - decltype and access control issues
Summary: decltype and access control issues
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.1
: P3 normal
Target Milestone: 12.0
Assignee: Patrick Palka
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-09-26 07:28 UTC by Roger Ferrer Ibanez
Modified: 2023-12-11 17:00 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.2, 4.9.1, 5.0
Last reconfirmed: 2021-08-01 00:00:00


Attachments
Testcase (184 bytes, text/x-c++src)
2014-09-26 07:29 UTC, Roger Ferrer Ibanez
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Roger Ferrer Ibanez 2014-09-26 07:28:29 UTC
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,
Comment 1 Roger Ferrer Ibanez 2014-09-26 07:29:30 UTC
Created attachment 33578 [details]
Testcase
Comment 2 Patrick Palka 2023-12-08 20:29:10 UTC
This seems to be fixed for GCC 12+ by r12-4453-g79802c5dcc043a.  Before closing the PR we should add this testcase to the testsuite.
Comment 3 GCC Commits 2023-12-11 16:59:45 UTC
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.
Comment 4 Patrick Palka 2023-12-11 17:00:36 UTC
Fixed.