<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - friend definition in nested class has private access to enclosing class"
href="https://llvm.org/bugs/show_bug.cgi?id=31747">31747</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>friend definition in nested class has private access to enclosing class
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>aurzenligl@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Clang accepts ill-formed code in -std=c++11/14/1z:
struct Outer
{
struct Inner
{
friend int get(Outer& o)
{
return o.x;
}
};
private:
int x;
};
Legal basis (based on c++11 standard):
7.3.1.2[3], 11.3[6]: in-class friend function definition
is a namespace member
3.4.1[9], 11.3[7]: in-class friend function definition
has member function lexical scope
11.7[1]: in-nested-class function definition
can access private members of enclosing class
9.7[4]: in-nested-class friend function definition
has no special access rights to members of an enclosing class
It seems that explicit exception in 9.7[4] is not respected: "(...) friend
function (...) has no special access rights to members of an enclosing class".
There's no warning with -Wall -Wextra -pedantic on clang-3.5, newer and trunk.
I'd expect compilation to fail with error. Other compilers (gcc, msvc, icc)
fail as expected, noting that in given context x is private.
In c++98 code is ill-formed as well and clang incorrectly compiles it silently.
In c++98 access from nested to enclosing class privates is illegal (11.8[1]
c++03). In c++11 above clause was relaxed (11.7[1] c++11), but this shouldn't
change the meaning of -std=c++98/03 in clang.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>