Topic: Typo in the Working Draft of the C++ Standard # 3337
Author: Vlad from Moscow <vlad.moscow@mail.ru>
Date: Tue, 17 Apr 2012 23:11:23 -0700 (PDT)
Raw View
I found a typo in the Working Draft of the C++ Standard #3337 in
paragraph #2 of the section 11.3 Friends. There is the following
example
[ Example:
class A {
class B { };
friend class X;
};
struct X : A::B { // OK: A::B accessible to friend
A::B mx; // OK: A::B accessible to member of friend
class Y {
A::B my; // OK: A::B accessible to nested member of friend
};
};
end example ]
It is obvious that instaed of struct X : A::B shall be class X : A::B
because the friend declaration of X uses specifier class.
Maybe this typo is present in the C++ Standard. It should be checked.
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Pete Becker<pete@versatilecoding.com>
Date: Wed, 18 Apr 2012 08:54:34 -0700 (PDT)
Raw View
On 2012-04-18 06:11:23 +0000, Vlad from Moscow said:
> I found a typo in the Working Draft of the C++ Standard #3337 in
> paragraph #2 of the section 11.3 Friends. There is the following
> example
>
> [ Example:
> class A {
> class B { };
> friend class X;
> };
> struct X : A::B { // OK: A::B accessible to friend
> A::B mx; // OK: A::B accessible to member of friend
> class Y {
> A::B my; // OK: A::B accessible to nested member of friend
> };
> };
> end example ]
>
> It is obvious that instaed of struct X : A::B shall be class X : A::B
> because the friend declaration of X uses specifier class.
> Maybe this typo is present in the C++ Standard. It should be checked.
It's the same in the standard. Probably should be changed, for clarity.
But my recollection is (I haven't looked it up) that struct, class, and
even union can be used interchangeably in a forward declaration; it's
only at the point of definition that the keyword matters.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?UTF-8?B?RGFuaWVsIEtyw7xnbGVy?=<daniel.kruegler@googlemail.com>
Date: Thu, 19 Apr 2012 11:08:12 -0700 (PDT)
Raw View
Am 18.04.2012 17:54, schrieb Pete Becker:
> On 2012-04-18 06:11:23 +0000, Vlad from Moscow said:
>
>> I found a typo in the Working Draft of the C++ Standard #3337 in
>> paragraph #2 of the section 11.3 Friends. There is the following
>> example
>>
>> [ Example:
>> class A {
>> class B { };
>> friend class X;
>> };
>> struct X : A::B { // OK: A::B accessible to friend
>> A::B mx; // OK: A::B accessible to member of friend
>> class Y {
>> A::B my; // OK: A::B accessible to nested member of friend
>> };
>> };
>> end example ]
>>
>> It is obvious that instaed of struct X : A::B shall be class X : A::B
>> because the friend declaration of X uses specifier class.
>> Maybe this typo is present in the C++ Standard. It should be checked.
>
> It's the same in the standard. Probably should be changed, for clarity.
Actually I think it should stay, because it simply confirms that struct
and class are equivalent for declarations. This is not the first time
that someone believed that both class-keys would be different in
non-defining declarations. Actually, there also exists at least one
compiler, which can produce defective code, when declaring
class X;
in one place and
struct X;
in another. This is clearly a compiler defect, but this problem often
has the effect that kind of misunderstandings stay alive.
> But my recollection is (I haven't looked it up) that struct, class, and
> even union can be used interchangeably in a forward declaration; it's
> only at the point of definition that the keyword matters.
struct and class are equivalent class-keys, but both differ from union,
see 7.1.6.3 p3:
"Thus, in any elaborated-type-specifier, the enum keyword shall be used
to refer to an enumeration (7.2), the union class-key shall be used to
refer to a union (Clause 9), and either the class or struct class-key
shall be used to refer to a class (Clause 9) declared using the class or
struct class-key."
Greetings from Bremen,
Daniel
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Vlad from Moscow<vlad.moscow@mail.ru>
Date: Thu, 19 Apr 2012 11:08:50 -0700 (PDT)
Raw View
On 18 , 19:54, Pete Becker<p...@versatilecoding.com> wrote:
> On 2012-04-18 06:11:23 +0000, Vlad from Moscow said:
>
>
>
>
>
> > I found a typo in the Working Draft of the C++ Standard #3337 in
> > paragraph #2 of the section 11.3 Friends. There is the following
> > example
>
> > [ Example:
> > class A {
> > class B { };
> > friend class X;
> > };
> > struct X : A::B { // OK: A::B accessible to friend
> > A::B mx; // OK: A::B accessible to member of friend
> > class Y {
> > A::B my; // OK: A::B accessible to nested member of friend
> > };
> > };
> > end example ]
>
> > It is obvious that instaed of struct X : A::B shall be class X : A::B
> > because the friend declaration of X uses specifier class.
> > Maybe this typo is present in the C++ Standard. It should be checked.
>
> It's the same in the standard. Probably should be changed, for clarity.
> But my recollection is (I haven't looked it up) that struct, class, and
> even union can be used interchangeably in a forward declaration; it's
> only at the point of definition that the keyword matters.
>
> --
> Pete
> Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
> Standard C++ Library Extensions: a Tutorial and Reference
> (www.petebecker.com/tr1book)
>
No, class-key may not be used interchangeably. For example in section
7.1.6.3 "Elaborated type specifiers" of the C++ 2011 Standard there is
written:
"3 The class-key or enum keyword present in the elaborated-type-
specifier shall agree in kind with the declaration to which the name
in the elaborated-type-specifier refers. This rule also applies to the
form of elaborated-type-specifier that declares a class-name or friend
class since it can be construed as referring to
the definition of the class. Thus, in any elaborated-type-specifier,
the enum keyword shall be used to refer to an enumeration (7.2), the
union class-key shall be used to refer to a union (Clause 9), and
either the class or struct class-key shall be used to refer to a class
(Clause 9) declared using the class or struct class-key."
> [ comp.std.c++ is moderated. To submit articles, try posting with your ]
> [ newsreader. If that fails, use mailto:std-cpp-sub...@vandevoorde.com ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]