www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - [bug] two-phase name lookup

↑ ↓ ← Christof Meerwald <cmeerw web.de> writes:
The following test-case should print "OK" (see 14.6.2 (3)), but I get "FAIL"
with DMC 8.44.6n:

#include <stdio.h>

void f()
{
  printf("OK\n");
}

template<class T>
struct A
{
  void f()
  {
    printf("FAIL\n");
  }
};

template<class T>
struct B
  : A<T>
{
  void g()
  {
    f();
  }
};

int main()
{
  B<int> b;
  b.g();

  return 0;
}


bye, Christof

-- 
http://cmeerw.org
mailto:cmeerw at web.de                       xmpp:cmeerw at cmeerw.org

...and what have you contributed to the Net?
Aug 06 2005
→ "Walter" <newshound digitalmars.com> writes:
This is taken care of in the new beta.
Aug 20 2005
jay.a.carlson gmail.com writes:
I am sure Christof is much more knowledgeable than myself but I have to ask:

why not replace this            with this

template<class T>               template<class T>
struct B : A<T>                 struct B : A<T>
{                               { 
void g()  { f();  }           void g()  { ::f();  } // only modified line
};                              };       

A<T> has a function f() and global namespace has a function f().
Using ::f() explicity calls the global function f() therefore removing the
ambiguity.  Is the original code really a compiler failure?

(OK I didn't test it on DM because I am at work. 
But it did work an another compiler.)

/r
Jay Carlson

In article <newscache$4w3tki$4t2$1 msgid.cmeerw.org>, Christof Meerwald says...
The following test-case should print "OK" (see 14.6.2 (3)), but I get "FAIL"
with DMC 8.44.6n:

#include <stdio.h>

void f()
{
  printf("OK\n");
}

template<class T>
struct A
{
  void f()
  {
    printf("FAIL\n");
  }
};

template<class T>
struct B
  : A<T>
{
  void g()
  {
    f();
  }
};

int main()
{
  B<int> b;
  b.g();

  return 0;
}


bye, Christof

-- 
http://cmeerw.org
mailto:cmeerw at web.de                       xmpp:cmeerw at cmeerw.org

...and what have you contributed to the Net?

jay.a.carlson gmail.com
Aug 24 2005
↑ ↓ → "Walter" <newshound digitalmars.com> writes:
<jay.a.carlson gmail.com> wrote in message
news:dejfag$213l$1 digitaldaemon.com...
 I am sure Christof is much more knowledgeable than myself but I have to

 why not replace this            with this

 template<class T>               template<class T>
 struct B : A<T>                 struct B : A<T>
 {                               {
 void g()  { f();  }           void g()  { ::f();  } // only modified line
 };                              };

 A<T> has a function f() and global namespace has a function f().
 Using ::f() explicity calls the global function f() therefore removing the
 ambiguity.  Is the original code really a compiler failure?

Christof writes code to test compiler features and standards conformance, so the bug reports he posts are usually not the result of some bug he's trying to work around. He's got a nice web page up comparing standards conformance of various C++ compilers: http:///cmeerw.org. I owe Christof a big debt of gratitude as he's the one who figured out everything that was going wrong with DMC++'s early template implementation and distilled them all down to short & sweet bug reports.
Aug 25 2005