What the heck?

Discussion in 'C++' started by John Femiani, Nov 7, 2007.

  1. John Femiani

    John Femiani Guest

    My message does not show up at all. Here it is again:

    IN g++ 3.4.2 this does not compile:

    #include <iostream>


    template<class T>
    struct A {
    int member;
    };

    emplate<class T>
    struct B: A<T>
    {
    void somefunc() {
    std::cout << member << std::endl;
    }
    };


    int main(int argc, char* argv[]){
    B<int> b;
    b.somefunc();
    }


    But it does on vc8.

    Should this compile? Is there a bug on vc8? or g++?

    g++ gives this error message:

    test.cpp:15: error: `member' undeclared (first use this function)

    replacing line 15 by:

    std::cout << this->member << std::endl;
    fixes it.

    Also if I make A and B _not_ use templates all is fine.

    My question is, is this a g++ bug or a vc8 bug?

    -- John
     
    John Femiani, Nov 7, 2007
    #1
    1. Advertising

  2. John Femiani

    Kira Yamato Guest

    On 2007-11-07 03:06:04 -0500, John Femiani <> said:

    > My message does not show up at all. Here it is again:
    >
    > IN g++ 3.4.2 this does not compile:
    >
    > #include <iostream>
    >
    >
    > template<class T>
    > struct A {
    > int member;
    > };
    >
    > emplate<class T>
    > struct B: A<T>
    > {
    > void somefunc() {
    > std::cout << member << std::endl;
    > }
    > };
    >
    >
    > int main(int argc, char* argv[]){
    > B<int> b;
    > b.somefunc();
    > }
    >
    >
    > But it does on vc8.
    >
    > Should this compile? Is there a bug on vc8? or g++?
    >
    > g++ gives this error message:
    >
    > test.cpp:15: error: `member' undeclared (first use this function)
    >
    > replacing line 15 by:
    >
    > std::cout << this->member << std::endl;
    > fixes it.
    >
    > Also if I make A and B _not_ use templates all is fine.
    >
    > My question is, is this a g++ bug or a vc8 bug?
    >
    > -- John


    You just discovered the "two-stage name lookup" with "dependent" and
    "non-dependent" names.

    The answer is in here: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html

    It works on VC because, as I've been told, VC does not quite follow the
    standard.

    --

    -kira
     
    Kira Yamato, Nov 7, 2007
    #2
    1. Advertising

  3. John Femiani

    Bo Persson Guest

    Kira Yamato wrote:
    :: On 2007-11-07 03:06:04 -0500, John Femiani
    :: <> said:
    ::
    ::: My message does not show up at all. Here it is again:
    :::
    ::: IN g++ 3.4.2 this does not compile:
    :::
    ::: #include <iostream>
    :::
    :::
    ::: template<class T>
    ::: struct A {
    ::: int member;
    ::: };
    :::
    ::: emplate<class T>
    ::: struct B: A<T>
    ::: {
    ::: void somefunc() {
    ::: std::cout << member << std::endl;
    ::: }
    ::: };
    :::
    :::
    ::: int main(int argc, char* argv[]){
    ::: B<int> b;
    ::: b.somefunc();
    ::: }
    :::
    :::
    ::: But it does on vc8.
    :::
    ::: Should this compile? Is there a bug on vc8? or g++?
    :::
    ::: g++ gives this error message:
    :::
    ::: test.cpp:15: error: `member' undeclared (first use this function)
    :::
    ::: replacing line 15 by:
    :::
    ::: std::cout << this->member << std::endl;
    ::: fixes it.
    :::
    ::: Also if I make A and B _not_ use templates all is fine.
    :::
    ::: My question is, is this a g++ bug or a vc8 bug?
    :::
    ::: -- John
    ::
    :: You just discovered the "two-stage name lookup" with "dependent"
    :: and "non-dependent" names.
    ::
    :: The answer is in here:
    :: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html
    ::
    :: It works on VC because, as I've been told, VC does not quite
    :: follow the standard.

    Not following the standard is considered an extension, so you have to
    select the "Disable Language Extensions" option (/Za).


    Bo Persson
     
    Bo Persson, Nov 7, 2007
    #3
  4. On 2007-11-07 19:12, Bo Persson wrote:
    > Kira Yamato wrote:
    > :: On 2007-11-07 03:06:04 -0500, John Femiani
    > :: <> said:
    > ::
    > ::: My message does not show up at all. Here it is again:
    > :::
    > ::: IN g++ 3.4.2 this does not compile:
    > :::
    > ::: #include <iostream>
    > :::
    > :::
    > ::: template<class T>
    > ::: struct A {
    > ::: int member;
    > ::: };
    > :::
    > ::: emplate<class T>
    > ::: struct B: A<T>
    > ::: {
    > ::: void somefunc() {
    > ::: std::cout << member << std::endl;
    > ::: }
    > ::: };
    > :::
    > :::
    > ::: int main(int argc, char* argv[]){
    > ::: B<int> b;
    > ::: b.somefunc();
    > ::: }
    > :::
    > :::
    > ::: But it does on vc8.
    > :::
    > ::: Should this compile? Is there a bug on vc8? or g++?
    > :::
    > ::: g++ gives this error message:
    > :::
    > ::: test.cpp:15: error: `member' undeclared (first use this function)
    > :::
    > ::: replacing line 15 by:
    > :::
    > ::: std::cout << this->member << std::endl;
    > ::: fixes it.
    > :::
    > ::: Also if I make A and B _not_ use templates all is fine.
    > :::
    > ::: My question is, is this a g++ bug or a vc8 bug?
    > :::
    > ::: -- John
    > ::
    > :: You just discovered the "two-stage name lookup" with "dependent"
    > :: and "non-dependent" names.
    > ::
    > :: The answer is in here:
    > :: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html
    > ::
    > :: It works on VC because, as I've been told, VC does not quite
    > :: follow the standard.
    >
    > Not following the standard is considered an extension, so you have to
    > select the "Disable Language Extensions" option (/Za).


    Actually, it is my understanding that two-phase lookup is simply not
    implemented.

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Nov 7, 2007
    #4
  5. John Femiani

    Kira Yamato Guest

    On 2007-11-07 13:54:49 -0500, Erik Wikström <> said:

    > On 2007-11-07 19:12, Bo Persson wrote:
    >> Kira Yamato wrote:
    >> :: On 2007-11-07 03:06:04 -0500, John Femiani
    >> :: <> said:
    >> ::
    >> ::: My message does not show up at all. Here it is again:
    >> :::
    >> ::: IN g++ 3.4.2 this does not compile:
    >> :::
    >> ::: #include <iostream>
    >> :::
    >> :::
    >> ::: template<class T>
    >> ::: struct A {
    >> ::: int member;
    >> ::: };
    >> :::
    >> ::: emplate<class T>
    >> ::: struct B: A<T>
    >> ::: {
    >> ::: void somefunc() {
    >> ::: std::cout << member << std::endl;
    >> ::: }
    >> ::: };
    >> :::
    >> :::
    >> ::: int main(int argc, char* argv[]){
    >> ::: B<int> b;
    >> ::: b.somefunc();
    >> ::: }
    >> :::
    >> :::
    >> ::: But it does on vc8.
    >> :::
    >> ::: Should this compile? Is there a bug on vc8? or g++?
    >> :::
    >> ::: g++ gives this error message:
    >> :::
    >> ::: test.cpp:15: error: `member' undeclared (first use this function)
    >> :::
    >> ::: replacing line 15 by:
    >> :::
    >> ::: std::cout << this->member << std::endl;
    >> ::: fixes it.
    >> :::
    >> ::: Also if I make A and B _not_ use templates all is fine.
    >> :::
    >> ::: My question is, is this a g++ bug or a vc8 bug?
    >> :::
    >> ::: -- John
    >> ::
    >> :: You just discovered the "two-stage name lookup" with "dependent"
    >> :: and "non-dependent" names.
    >> ::
    >> :: The answer is in here:
    >> :: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html
    >> ::
    >> :: It works on VC because, as I've been told, VC does not quite
    >> :: follow the standard.
    >>
    >> Not following the standard is considered an extension, so you have to
    >> select the "Disable Language Extensions" option (/Za).

    >
    > Actually, it is my understanding that two-phase lookup is simply not
    > implemented.


    From the same link above, I quote,

    "This distinction between lookup of dependent and non-dependent names
    is called two-stage (or dependent) name lookup. G++ implements it since
    version 3.4."

    I'm running g++ 4.0.1, but I have not written any code to test it yet.
    But the OP seems to have tested it on g++ 3.4.2.

    --

    -kira
     
    Kira Yamato, Nov 7, 2007
    #5
  6. John Femiani

    Bo Persson Guest

    Erik Wikström wrote:
    :: On 2007-11-07 19:12, Bo Persson wrote:
    ::: Kira Yamato wrote:
    ::::: On 2007-11-07 03:06:04 -0500, John Femiani
    ::::: <> said:
    :::::
    :::::: My message does not show up at all. Here it is again:
    ::::::
    :::::: IN g++ 3.4.2 this does not compile:
    ::::::
    :::::: #include <iostream>
    ::::::
    ::::::
    :::::: template<class T>
    :::::: struct A {
    :::::: int member;
    :::::: };
    ::::::
    :::::: emplate<class T>
    :::::: struct B: A<T>
    :::::: {
    :::::: void somefunc() {
    :::::: std::cout << member << std::endl;
    :::::: }
    :::::: };
    ::::::
    ::::::
    :::::: int main(int argc, char* argv[]){
    :::::: B<int> b;
    :::::: b.somefunc();
    :::::: }
    ::::::
    ::::::
    :::::: But it does on vc8.
    ::::::
    :::::: Should this compile? Is there a bug on vc8? or g++?
    ::::::
    :::::: g++ gives this error message:
    ::::::
    :::::: test.cpp:15: error: `member' undeclared (first use this
    :::::: function)
    ::::::
    :::::: replacing line 15 by:
    ::::::
    :::::: std::cout << this->member << std::endl;
    :::::: fixes it.
    ::::::
    :::::: Also if I make A and B _not_ use templates all is fine.
    ::::::
    :::::: My question is, is this a g++ bug or a vc8 bug?
    ::::::
    :::::: -- John
    :::::
    ::::: You just discovered the "two-stage name lookup" with "dependent"
    ::::: and "non-dependent" names.
    :::::
    ::::: The answer is in here:
    ::::: http://gcc.gnu.org/onlinedocs/gcc/Name-lookup.html
    :::::
    ::::: It works on VC because, as I've been told, VC does not quite
    ::::: follow the standard.
    :::
    ::: Not following the standard is considered an extension, so you
    ::: have to select the "Disable Language Extensions" option (/Za).
    ::
    :: Actually, it is my understanding that two-phase lookup is simply
    :: not implemented.

    Not properly, no. But this is about finding members of dependent base
    classes, which is implemented (if you ask for it).

    The usual problem is, of course, that if you use /Za windows.h doesn't
    compile. :-(


    Bo Persson
     
    Bo Persson, Nov 7, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Nicholson

    what the heck is "ASP.NET Web Matrix" ?

    Martin Nicholson, Oct 27, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    430
    Steve C. Orr [MVP, MCSD]
    Dec 15, 2003
  2. Paul W

    what the heck?!?!?!?

    Paul W, Apr 6, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    447
    Paul W
    Apr 6, 2005
  3. =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=

    Fill a cell with a control -- how the heck?

    =?Utf-8?B?V2lsbGlhbSBTdWxsaXZhbg==?=, Aug 18, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    472
    Eliyahu Goldin
    Aug 18, 2005
  4. tfsmag
    Replies:
    4
    Views:
    618
    =?Utf-8?B?U3JlZWppdGggUmFt?=
    Oct 21, 2005
  5. Replies:
    5
    Views:
    414
    Kevin McMurtrie
    Mar 20, 2005
Loading...

Share This Page