www.digitalmars.com         C & C++   DMDScript  

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

reply 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
next sibling parent "Walter" <newshound digitalmars.com> writes:
This is taken care of in the new beta.
Aug 20 2005
prev sibling next sibling parent reply 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
parent "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
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?
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
prev sibling parent Travis <Travisseal gmail.com> writes:
try this---
#include <stdio.h>
#include <iostream>
#include <conio.h>
using namespace std;
int main();

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();

  getchar();
  return 0;
}
Apr 28 2008