以下のコードをコンパイルするとエラーになる。
class X
{
int value ;
friend class Y ;
} ;
class Y
{
public :
template < typename T >
static auto f(T t) -> decltype( t.value )
{
return t.value ;
}
} ;
int main()
{
X x ;
Y::f(x) ;
}
gccは、おそらくバグのため、このコードをコンパイルできない。興味深いのは、エラーメッセージだ。
In function 'int main()': error: 'int X::value' is private error: within this context
そもそもmain関数内というのが間違っている。。X::valueにアクセスしているのは、Y::get関数である。
試しに、クラスXからmain関数をfriendにしてみると。
class X
{
int value ;
friend class Y ;
friend int main() ;
} ;
なぜかコンパイルが通ってしまう。明らかにおかしい。
なかなか笑えるバグだ。発見者はバグレポートを投げたほうがいいと思う。
No comments:
Post a Comment