On Wednesday, October 1, 2014 8:52:41 AM UTC-3, Louis Krupp wrote:
> On Wed, 01 Oct 2014 23:46:57 +1300, Ian Collins <ian-news@****.com>
>
> wrote:
>
>
>
> >Chairman Mao wrote:
>
> >> I don't understand how this code compiles. For me, the function
>
> >> should be defined as `void f(const A::B& b)`, but g++ says that A::B
>
> >> is not a type.
>
> >>
>
> >> struct A { struct B* p; };
>
> >>
>
> >> void f(const B& b ) { }
>
> >>
>
> >> int main() { A a; f(*a.p); }
>
> >
>
> >Where is B declared?
>
>
>
> As far as I can tell, B is *declared* on the third line, when A.p is
>
> defined as type struct B*, but B is never completely *defined*.
>
>
>
>
>
> f(const B& b) is OK because it never actually *does* anything with its
>
> argument.
>
>
>
> Louis
I believe this has to with §3.3.2/6, but I can't see the exact relation between this paragraph and the code.
§3.3.2/6:
"The point of declaration of a class first declared in an elaborated-type-specifier is as follows:
-- for a declaration of the form class-key attribute-specifier-seqopt identifier;
the identifier is declared to be a class-name in the scope that contains the declaration, otherwise
-- for an elaborated-type-specifier of the form class-key identifier if the elaborated-type-specifier is used in the decl-specifier-seq or parameter-declaration-clause of a function defined in namespace scope, the identifier is declared as a class-name in the namespace that
contains the declaration; otherwise, except as a friend declaration, the identifier is declared in the smallest namespace or block scope that contains the declaration. [ Note: These rules also apply within templates. --end note ] [ Note: Other forms of elaborated-type-specifier do not declare a new name,
and therefore must refer to an existing type-name. See 3.4.4 and 7.1.6.3. --end note ]