Bug 64216 - Function template can access private sub class without being friend
Summary: Function template can access private sub class without being friend
Status: RESOLVED DUPLICATE of bug 41437
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-08 00:52 UTC by Yichao Yu
Modified: 2014-12-08 10:28 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-12-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yichao Yu 2014-12-08 00:52:19 UTC
The following code compiles on g++ 4.9.2 while it shouldn't.
Accessing private members and access in non-templates are properly checked. However, a function template can actually access any private sub-class without being a friend. This problem exist for all standards I've tried ((gnu|c)++(98|03|11|14))

The code is properly rejected by clang++ 3.5.0.

```
//

class C {
    struct T2 {
    };
    static void f() {}
};

template<typename T>
static inline void
f(T)
{
    // C::f(); // This generates an error correctly
    C::T2 __attribute__((unused)) v2; // This does not generate an error
}

int
main()
{
    // C::T2 v2; // This also generates an error correctly
    f(1);
    return 0;
}

```
Comment 1 Jonathan Wakely 2014-12-08 10:02:46 UTC
Almost certainly a duplicate of one of the bugs linked to PR59002, 
it looks nearly identical to PR41437
Comment 2 Jonathan Wakely 2014-12-08 10:28:51 UTC
Definitely a dup

*** This bug has been marked as a duplicate of bug 41437 ***