Topic: Question about name lookup example in section 3.4.1 of the standard


Author: Michael Greenberg <mgreenberg@scr.siemens.com>
Date: 1998/08/31
Raw View
In section 3.4.1 there is the following example:

typedef int f;
struct A {
    friend void f(A &) ;
    operator int() ;
    void g(A a) {
        f(a) ; // cast expression, not function call
   }
} ;

Is the example legal code? Doesn't the friend declaration of 'f'
conflict with the typedef 'f'?

If the example was in a class definition, it would make sense to me:

class foo {
    typedef int f;
    struct A {
        friend void f(A &) ;
        operator int() ;
        void g(A a) {
            f(a) ; // cast expression, not function call
       }
    } ; } ;




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Michael Greenberg <mgreenberg@scr.siemens.com>
Date: 1998/09/02
Raw View
In section 3.4.1 there is the following example:

typedef int f;
struct A {
    friend void f(A &) ;
    operator int() ;
    void g(A a) {
        f(a) ; // cast expression, not function call
   }
} ;

Is the example legal code? Doesn't the friend declaration of 'f'
conflict with the typedef 'f'?

If the example was in a class definition, it would make sense to me:

class foo {
    typedef int f;
    struct A {
        friend void f(A &) ;
        operator int() ;
        void g(A a) {
            f(a) ; // cast expression, not function call
       }
    } ; } ;
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1998/09/02
Raw View
Michael Greenberg <mgreenberg@scr.siemens.com> writes:

> In section 3.4.1 there is the following example:
>
> typedef int f;
> struct A {
>     friend void f(A &) ;
>     operator int() ;
>     void g(A a) {
>         f(a) ; // cast expression, not function call
>    }
> } ;
>
> Is the example legal code? Doesn't the friend declaration of 'f'
> conflict with the typedef 'f'?

It would appear so. The text making this illegal is somewhat spread,
but the Note in 3.3 [basic.scope]/4 deals with exactly this case

>> these restrictions apply to the declarative region into which a
>> name is introduced, which is not necessarily the same as the region
>> in which the declaration occurs. In particular,
>> elaborated=ADtype=ADspecifiers (3.3.1) and friend declarations (11.4)
>> may introduce a (possibly not visible) name into an enclosing
>> namespace; these restrictions apply to that region.

Someone should report this as a defect.

Regards,
Martin
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]