Topic: Example (N3092) about name lookup seems to be not compilable


Author: Faisal Vali <faisalv@gmail.com>
Date: Fri, 30 Apr 2010 11:39:05 CST
Raw View
On Apr 29, 6:52 pm, =?ISO-8859-1?Q?Daniel_Kr=FCgler?=
<daniel.krueg...@googlemail.c=.om> wrote:
> On Apr 29, 1:45 am, "Christophe Masson" <"cmasson [ a t ] castsoftware
> [d o t] com"@b1.fti.net> wrote:
>
> > the following example lies in the section 3.4.1 ([basic.lookup.unqual]),
> > paragraph 3 of the current FCD (N 3092).
> > <snip>
> > //------- Example start ----------
> > typedef int f;
> > namespace N
> > {
> >    struct A
> >    {
> >        friend void f(A &);
> >        operator int();
> >        void g(A a)
> >        {
> >            int i = f(a); // f is the typedef, not the friend
> >                          // function: equivalent to int(a)
> >        }
> >    };}
>
> > //----- Example end --------------
> > <snip>
> > Is that an error in the FCD, are all compilers wrong, or am I missing
> > something ?
>
> The FCD wording is correct. Several current compilers do get that
> right, e.g.
> the current Comeau online or the most recent gcc 4.5.0-1.
<snip>

Agreed.

If I could ask a related question here -

Based on 11.4 (7) of the FCD - this should NOT compile - right?

typedef int f;
namespace N {
 struct A {
  friend void f(A a) { } // note: This is now a definition

  operator int();

  void g(A a) {
    int i = f(a);
  }
 };
}


Since 11.4 (7) states that the friend definition's name is in the
lexical scope of the class - the token 'f' should preferentially refer
to the function and not the typedef.

Or am I missing something?

thanks in advance,

Faisal Vali
Radiation Oncology
Loyola


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Christophe Masson" <"c.masson [ a t ] castsoftware [d o t] com"@b1.fti.net>
Date: Fri, 30 Apr 2010 15:23:58 CST
Raw View
OK, thanks to you.

Christophe Masson

"=?ISO-8859-1?Q?Daniel_Kr=FCgler?=" <daniel.kruegler@googlemail.c=.om>
a    crit dans le message de news:
fdaf377d-3be7-44ba-b83e-9ae78e8f320f@r11g2000yqa.googlegroups.com...
> On Apr 29, 1:45 am, "Christophe Masson" <"cmasson [ a t ] castsoftware
> [d o t] com"@b1.fti.net> wrote:
>
> [..]
>
>> the following example lies in the section 3.4.1 ([basic.lookup.unqual]),
>> paragraph 3 of the current FCD (N 3092).
>> This example has been slightly modified since the 2003 standard (it did
>> not compile then).
>>
>> //------- Example start ----------
>> typedef int f;
>> namespace N
>> {
>>    struct A
>>    {
>>        friend void f(A &);
>>        operator int();
>>        void g(A a)
>>        {
>>            int i = f(a); // f is the typedef, not the friend
>>                          // function: equivalent to int(a)
>>        }
>>    };}
>>
>> //----- Example end --------------
>>
>> But all compilers I have access to (MS VC++ 6.0 to 8, gcc, EDG) still
>> complain, this time about f(a) denoting a void (so it seems that they
>> interpret f(a) as a function call).
>> And so does the C++ parser I am working on :-).
>>
>> Is that an error in the FCD, are all compilers wrong, or am I missing
>> something ?
>
> The FCD wording is correct. Several current compilers do get that
> right, e.g.
> the current Comeau online or the most recent gcc 4.5.0-1.
> I just notice that VS2010 does not get this right, but I have not
> tested all
> compiler settings. If so, you might want to send a bug report to
> Microsoft.
>
> HTH & Greetings from Bremen,
>
> Daniel Kr=FCgler
>
>
> --
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use
> mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
> ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]
>



--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Fri, 30 Apr 2010 15:34:03 CST
Raw View
Faisal Vali wrote:

> On Apr 29, 6:52 pm, =?ISO-8859-1?Q?Daniel_Kr=FCgler?=
> <daniel.krueg...@googlemail.c=.om> wrote:
>> On Apr 29, 1:45 am, "Christophe Masson" <"cmasson [ a t ] castsoftware
>> [d o t] com"@b1.fti.net> wrote:
>>
>> > the following example lies in the section 3.4.1
>> > ([basic.lookup.unqual]), paragraph 3 of the current FCD (N 3092).
>> > <snip>
>> > //------- Example start ----------
>> > typedef int f;
>> > namespace N
>> > {
>> >    struct A
>> >    {
>> >        friend void f(A &);
>> >        operator int();
>> >        void g(A a)
>> >        {
>> >            int i = f(a); // f is the typedef, not the friend
>> >                          // function: equivalent to int(a)
>> >        }
>> >    };}
>>
>> > //----- Example end --------------
>> > <snip>
>> > Is that an error in the FCD, are all compilers wrong, or am I missing
>> > something ?
>>
>> The FCD wording is correct. Several current compilers do get that
>> right, e.g.
>> the current Comeau online or the most recent gcc 4.5.0-1.
> <snip>
>
> Agreed.
>
> If I could ask a related question here -
>
> Based on 11.4 (7) of the FCD - this should NOT compile - right?
>
> typedef int f;
> namespace N {
>  struct A {
>   friend void f(A a) { } // note: This is now a definition
>
>   operator int();
>
>   void g(A a) {
>     int i = f(a);
>   }
>  };
> }
>
>
> Since 11.4 (7) states that the friend definition's name is in the
> lexical scope of the class - the token 'f' should preferentially refer
> to the function and not the typedef.
>

It refers to the typedef. The saying that it is "in the (lexical) scope of
the class" means that the following is well-defined:

struct A {
 typedef int foo;
 friend void f() { foo a; }
};

While the following is not:

struct A {
 typedef int foo;
 friend void f();
};

void f() { foo a; }

See the lookup rules in 3.4.1 (9).

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Christophe Masson" <"cmasson [ a t ] castsoftware [d o t] com"@b1.fti.net>
Date: Wed, 28 Apr 2010 17:45:54 CST
Raw View
Dear Sirs,

the following example lies in the section 3.4.1 ([basic.lookup.unqual]),
paragraph 3 of the current FCD (N 3092).
This example has been slightly modified since the 2003 standard (it did
not compile then).

//------- Example start ----------
typedef int f;
namespace N
{
   struct A
   {
       friend void f(A &);
       operator int();
       void g(A a)
       {
           int i = f(a); // f is the typedef, not the friend
                         // function: equivalent to int(a)
       }
   };
}
//----- Example end --------------

But all compilers I have access to (MS VC++ 6.0 to 8, gcc, EDG) still
complain, this time about f(a) denoting a void (so it seems that they
interpret f(a) as a function call).
And so does the C++ parser I am working on :-).

Is that an error in the FCD, are all compilers wrong, or am I missing
something ?

Best regards.

Christophe Masson

cmasson /a t/ castsoftware /d o t/ com



--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Thu, 29 Apr 2010 17:51:02 CST
Raw View
Christophe Masson wrote:

> //------- Example start ----------
> typedef int f;
> namespace N
> {
> struct A
> {
> friend void f(A &);
> operator int();
> void g(A a)
> {
> int i = f(a); // f is the typedef, not the friend
> // function: equivalent to int(a)
> }
> };
> }
> //----- Example end --------------

Works fine in GCC and clang for me.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: =3D?ISO-8859-1?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.c=.om>
Date: Thu, 29 Apr 2010 17:52:31 CST
Raw View
On Apr 29, 1:45 am, "Christophe Masson" <"cmasson [ a t ] castsoftware
[d o t] com"@b1.fti.net> wrote:

[..]

> the following example lies in the section 3.4.1 ([basic.lookup.unqual]),
> paragraph 3 of the current FCD (N 3092).
> This example has been slightly modified since the 2003 standard (it did
> not compile then).
>
> //------- Example start ----------
> typedef int f;
> namespace N
> {
>    struct A
>    {
>        friend void f(A &);
>        operator int();
>        void g(A a)
>        {
>            int i = f(a); // f is the typedef, not the friend
>                          // function: equivalent to int(a)
>        }
>    };}
>
> //----- Example end --------------
>
> But all compilers I have access to (MS VC++ 6.0 to 8, gcc, EDG) still
> complain, this time about f(a) denoting a void (so it seems that they
> interpret f(a) as a function call).
> And so does the C++ parser I am working on :-).
>
> Is that an error in the FCD, are all compilers wrong, or am I missing
> something ?

The FCD wording is correct. Several current compilers do get that
right, e.g.
the current Comeau online or the most recent gcc 4.5.0-1.
I just notice that VS2010 does not get this right, but I have not
tested all
compiler settings. If so, you might want to send a bug report to
Microsoft.

HTH & Greetings from Bremen,

Daniel Kr=FCgler


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Paul Bibbings <paul.bibbings@gmail.com>
Date: Fri, 30 Apr 2010 11:38:38 CST
Raw View
"Christophe Masson" <"cmasson [ a t ] castsoftware [d o t]
com"@b1.fti.net> writes:

> Dear Sirs,
>
> the following example lies in the section 3.4.1 ([basic.lookup.unqual]),
> paragraph 3 of the current FCD (N 3092).
> This example has been slightly modified since the 2003 standard (it did
> not compile then).
>
> //------- Example start ----------
> typedef int f;
> namespace N
> {
>    struct A
>    {
>        friend void f(A &);
>        operator int();
>        void g(A a)
>        {
>            int i = f(a); // f is the typedef, not the friend
>                          // function: equivalent to int(a)
>        }
>    };
> }
> //----- Example end --------------
>
> But all compilers I have access to (MS VC++ 6.0 to 8, gcc, EDG) still
> complain, this time about f(a) denoting a void (so it seems that they
> interpret f(a) as a function call).

You don't say what version(s) of gcc you are using and which
complain(s).  I have to go right back to what I would consider a very
outdated (2004) gcc to have this fail:

  10:48:03 Paul Bibbings@JIJOU
  /cygdrive/d/CPPProjects/CLCPPM $i686-pc-cygwin-gcc-4.5.0 -c _3_4_1_3.cpp

  10:48:22 Paul Bibbings@JIJOU
  /cygdrive/d/CPPProjects/CLCPPM $i686-pc-cygwin-gcc-4.4.3 -c _3_4_1_3.cpp

  10:48:43 Paul Bibbings@JIJOU
  /cygdrive/d/CPPProjects/CLCPPM $i686-pc-cygwin-gcc-4.4.1 -c _3_4_1_3.cpp

  10:49:02 Paul Bibbings@JIJOU
  /cygdrive/d/CPPProjects/CLCPPM $gcc-4 --version && gcc-4 -c _3_4_1_3.cpp
  gcc-4 (GCC) 4.3.4 20090804 (release) 1
  Copyright (C) 2008 Free Software Foundation, Inc.

  10:50:53 Paul Bibbings@JIJOU
  /cygdrive/d/CPPProjects/CLCPPM $gcc-3 --version && gcc-3 -c _3_4_1_3.cpp
  gcc-3 (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
  Copyright (C) 2004 Free Software Foundation, Inc.

  _3_4_1_3.cpp: In member function `void N::A::g(N::A)':
  _3_4_1_3.cpp:7: error: void value not ignored as it ought to be

(Note: I have run the above invocations with `-std=c++98 -pedantic`,
getting the same results


I was, however, surprise to find that it fails still with VC++ 9.0

  d:\CPPProjects\CLCPPM>cl /EHsc -c _3_4_1_3.cpp
 Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01
 for 80x86
 Copyright (C) Microsoft Corporation.  All rights reserved.

 _3_4_1_3.cpp
 _3_4_1_3.cpp(7) : error C2440: 'initializing' : cannot convert from
    'void' to 'int'
 Expressions of type void cannot be converted to other types

Check out Comeau online (http://www.comeaucomputing.com/tryitout/),
usually a more than fair arbiter in questions of the "is the Standard
or my compiler wrong" type.

Regards

Paul Bibbings


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]