www.digitalmars.com         C & C++   DMDScript  

c++ - Another namespace bug

reply Christof Meerwald <cmeerw web.de> writes:
Here is another one:

namespace A
{
struct C
{
  C(int i)
  { }
};

namespace B
{
template<class T>
struct D
{
  D()
  {
    C c(3);
    // Error: undefined identifier 'C'
  }
};
}
}

int main()
{
  A::B::D<int> d;

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de
Dec 05 2002
next sibling parent Richard <fractal clark.net> writes:
In article <asnd0i$2jn0$1 digitaldaemon.com>, Christof Meerwald says...
Here is another one:
also, typedef int Int; namespace std { using ::Int; } namespace one { struct A { std::Int* test; }; void main() { } gets Int is not a member of namespace std at "std::Int* test" Richard
Dec 05 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
Another one:

namespace ns
{
struct A {};

template <class T>
struct B { };

template<>
struct B<A>
{
  typedef A iterator_category;
  // Error: ';' expected following declaration of struct member
};
}

int main()
{
  ns::B<ns::A> i;

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 05 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
And another one:

namespace ns
{
template<class T>
struct A
{
  static void f()
  { }
};

template<class T>
struct B
{
  void f()
  {
    A<T>::f();
    // Error: 'ns::A<>::f' previously declared as something else
    // It was declared as: void C func()
    // It is now declared: int C func()
  }
};
}

int main()
{
  ns::B<int> b;
  b.f();

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 06 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
Another one:

namespace ns
{
template<class T>
struct A
{
  void f();
};

template<class T>
void A<T>::f()
// Error: 'A' is not a class template
{ }
}


int main()
{
  ns::A<int> a;

  a.f();

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 06 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
Another one:

namespace ns
{
struct A
{
  A()
  { }
};

struct B
  : public ns::A
{
  B()
    : ns::A()
  // Error: 'ns' is not a member of struct 'ns::B'
  { }
};
}


int main()
{
  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 06 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
template<class T>
struct A
{ };

namespace ns
{
template<class T>
struct A
// Error: 'A' is already defined
{ };
}

int main()
{
  A<int> a;
  ns::A<int> ns_a;

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 07 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
template<class T>
struct A
{ };

namespace ns
{
using ::A;
}

int main()
{
  ns::A<int> a;
  // Error: '<' expected following 'A'

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 07 2002
prev sibling next sibling parent reply Christof Meerwald <cmeerw web.de> writes:
namespace ns1
{
template<class T>
struct A
{
  A() { }
  // Error: namespace 'ns2' does not enclose member '?0' of namespace 'ns1'
};
}

namespace ns2
{
void f()
{
  ns1::A<int> a;
}
}


int main()
{
  ns2::f();

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 08 2002
next sibling parent Richard <fractal clark.net> writes:
In article <at0k4t$hb5$1 digitaldaemon.com>, Christof Meerwald says...
namespace ns1
{
template<class T>
struct A
{
  A() { }
  // Error: namespace 'ns2' does not enclose member '?0' of namespace 'ns1'
This is a really nasty one that tends to cause protection fault when compiled if the code base is large enoough. Richard
Dec 09 2002
prev sibling parent Richard <fractal clark.net> writes:
In article <at0k4t$hb5$1 digitaldaemon.com>, Christof Meerwald says...
namespace ns1
{
template<class T>
struct A
{
  A() { }
  // Error: namespace 'ns2' does not enclose member '?0' of namespace 'ns1'
Ok, after a retest, the code provided in Christof's test case causes a protection fault with .8 - as an aside, the dll version of the compiler is fine. smake produced -> SC -cpp -J -mn -C -WA -S -3 -a8 -c -gf -D_CONSOLE=1 -otest.obj test.cpp Richard
Dec 09 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
namespace ns
{
template<class T>
struct A
{ };
}

using ns::A;

struct B
  : public A<int>
  // Error: 'A' is not a struct or a class
{ };


int main()
{
  B b;

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 09 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
namespace ns1
{
struct A
{
  static int value;
};

int A::value = 0;
}

namespace ns2
{
struct A
{
  int f()
  {
    return ns1::A::value;
    // Error: 'A' must be a public base class of 'A'
  }
};
}

int main()
{
  ns2::A a;

  return a.f();
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 09 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
namespace ns
{
template<class T>
struct A
{ };

typedef A<char> B;
}

using ns::B;

struct C
  : public B
  // Error: undefined identifier 'B'
{ };


int main()
{
  C c;

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 11 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
namespace ns
{
struct A
{
  void f();
};

struct B
{ };
}

void ns::A::f()
{
  B b;
  // Error: undefined identifier 'B'
}


int main()
{
  ns::A a;

  return 0;
}


(see 3.4.1 Unqualified name lookup [basic.lookup.unqual], paragraph 8, of
the C++ Standard)


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 11 2002
prev sibling next sibling parent reply Christof Meerwald <cmeerw web.de> writes:
#include <stdio.h>

struct A
{
  friend int f(int i)
  {
    return 1;
  }
};

int f(long i)
{
  return 0;
}


int main()
{
  printf("%d\n", f(0));
}


AFAIK, f(long) should be invoked and not f(int). See 7.3.1.2 Namespace
member definitions [namespace.memdef], paragraph 3, of the C++ standard.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 14 2002
next sibling parent "Walter" <walter digitalmars.com> writes:
Ah, no rest for the wicked <g>.

"Christof Meerwald" <cmeerw web.de> wrote in message
news:atgjkb$l63$1 digitaldaemon.com...
 #include <stdio.h>

 struct A
 {
   friend int f(int i)
   {
     return 1;
   }
 };

 int f(long i)
 {
   return 0;
 }


 int main()
 {
   printf("%d\n", f(0));
 }


 AFAIK, f(long) should be invoked and not f(int). See 7.3.1.2 Namespace
 member definitions [namespace.memdef], paragraph 3, of the C++ standard.


 bye, Christof

 --
 http://cmeerw.org                                 JID: cmeerw jabber.at
 mailto cmeerw at web.de

 ...and what have you contributed to the Net?
Dec 14 2002
prev sibling next sibling parent Richard <fractal clark.net> writes:
Not sure if Christof posted this yet..

namespace one {

template<class T>
struct Types {
typedef int Int;
};

}

template<class T,
class  U = one::Types<int>::Int>
// Error: : no type for argument 'Int'
// Internal error: struct 2797

struct Values
{
typedef U type;
};

void main() {
typedef Values<int>::type def;
}

I tried to find chapter and verse for this but could only find 14.6.4 Dependent
name resolution.. and I'm not even sure it really applies. Man, Christof is
really brilliant. How did he get so smart?

Richard
Dec 15 2002
prev sibling parent reply "Walter" <walter digitalmars.com> writes:
I believe DMC++ is behaving correctly here. f(int i) is not declared in a
namespace, but in a non-local class, which according to 7.3.1.2-3 will
become "a member of the innermost enclosing namespace", which in this
instance is the global namespace. Hence, it should be found via normal
overload rules.

"Christof Meerwald" <cmeerw web.de> wrote in message
news:atgjkb$l63$1 digitaldaemon.com...
 #include <stdio.h>

 struct A
 {
   friend int f(int i)
   {
     return 1;
   }
 };

 int f(long i)
 {
   return 0;
 }


 int main()
 {
   printf("%d\n", f(0));
 }


 AFAIK, f(long) should be invoked and not f(int). See 7.3.1.2 Namespace
 member definitions [namespace.memdef], paragraph 3, of the C++ standard.


 bye, Christof

 --
 http://cmeerw.org                                 JID: cmeerw jabber.at
 mailto cmeerw at web.de

 ...and what have you contributed to the Net?
Dec 17 2002
parent reply Christof Meerwald <cmeerw web.de> writes:
On Tue, 17 Dec 2002 01:12:13 -0800, Walter wrote:
 I believe DMC++ is behaving correctly here. f(int i) is not declared in a
 namespace, but in a non-local class, which according to 7.3.1.2-3 will
 become "a member of the innermost enclosing namespace", which in this
 instance is the global namespace. Hence, it should be found via normal
 overload rules.
But the next sentence in the standard is: "The name of the friend is not found by simple name lookup until a matching declaration is provided in that namespace scope (either before or after the class declaration granting friendship)."
 "Christof Meerwald" <cmeerw web.de> wrote in message
 news:atgjkb$l63$1 digitaldaemon.com...
 #include <stdio.h>

 struct A
 {
   friend int f(int i)
   {
     return 1;
   }
 };

 int f(long i)
 {
   return 0;
 }


 int main()
 {
   printf("%d\n", f(0));
 }


 AFAIK, f(long) should be invoked and not f(int). See 7.3.1.2 Namespace
 member definitions [namespace.memdef], paragraph 3, of the C++ standard.
bye, Christof -- http://cmeerw.org JID: cmeerw jabber.at mailto cmeerw at web.de ...and what have you contributed to the Net?
Dec 17 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Christof Meerwald" <cmeerw web.de> wrote in message
news:atnudj$13hp$1 digitaldaemon.com...
 On Tue, 17 Dec 2002 01:12:13 -0800, Walter wrote:
 I believe DMC++ is behaving correctly here. f(int i) is not declared in
a
 namespace, but in a non-local class, which according to 7.3.1.2-3 will
 become "a member of the innermost enclosing namespace", which in this
 instance is the global namespace. Hence, it should be found via normal
 overload rules.
But the next sentence in the standard is: "The name of the friend is not found by simple name lookup until a matching declaration is provided in
that
 namespace scope (either before or after the class declaration granting
 friendship)."
True, but the example is a definition, not a declaration, which I believe changed things. Is this example from boost?
Dec 17 2002
next sibling parent Richard <fractal clark.net> writes:
Not sure about the analysis of this, but it works fine if I remove namespace
definitions.

namespace one {

template<class T> struct A { };

template<class T> A<T>& fn(A<T>& t) { return t; }

typedef A<int> Type;

}

using one::Type;
using one::fn;

void main() {

Type i;
Type j = fn(i);
// ambiguous reference to symbol
// Had: one::fn(A<T>&)
// and: one::fn(A<T>&)

}

Richard
Dec 19 2002
prev sibling parent reply Christof Meerwald <cmeerw web.de> writes:
On Tue, 17 Dec 2002 12:17:58 -0800, Walter wrote:
 "Christof Meerwald" <cmeerw web.de> wrote in message
 news:atnudj$13hp$1 digitaldaemon.com...
 On Tue, 17 Dec 2002 01:12:13 -0800, Walter wrote:
 I believe DMC++ is behaving correctly here. f(int i) is not declared in
a
 namespace, but in a non-local class, which according to 7.3.1.2-3 will
 become "a member of the innermost enclosing namespace", which in this
 instance is the global namespace. Hence, it should be found via normal
 overload rules.
But the next sentence in the standard is: "The name of the friend is not found by simple name lookup until a matching declaration is provided in
that
 namespace scope (either before or after the class declaration granting
 friendship)."
True, but the example is a definition, not a declaration, which I believe changed things. Is this example from boost?
Hmm, just found an example in the C++ standard, see 14.6.5 Friend names declared within a class template [temp.inject], paragraph 2. BTW, the example is not from Boost. It's inspired by some code from omniORB, but it's not causing any real trouble as most other compilers also get it wrong (including gcc 3.0) - but I am still hoping that I am right... bye, Christof -- http://cmeerw.org JID: cmeerw jabber.at mailto cmeerw at web.de ...and what have you contributed to the Net?
Dec 22 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Christof Meerwald" <cmeerw web.de> wrote in message
news:au4cno$166n$1 digitaldaemon.com...
 BTW, the example is not from Boost. It's inspired by some code from
omniORB,
 but it's not causing any real trouble as most other compilers also get it
 wrong (including gcc 3.0) - but I am still hoping that I am right...
Ok. I'll keep it on the active bug list for now, but I'll prioritize the other problems first. If practical, when you post bugs, let me know if they are showstoppers for your work or not. Thanks, -Walter
Dec 22 2002
next sibling parent reply "Matthew Wilson" <dmd synesis.com.au> writes:
I presume that goes for all of us, yes?

Matthew

"Walter" <walter digitalmars.com> wrote in message
news:au4toe$1hl3$1 digitaldaemon.com...
 "Christof Meerwald" <cmeerw web.de> wrote in message
 news:au4cno$166n$1 digitaldaemon.com...
 BTW, the example is not from Boost. It's inspired by some code from
omniORB,
 but it's not causing any real trouble as most other compilers also get
it
 wrong (including gcc 3.0) - but I am still hoping that I am right...
Ok. I'll keep it on the active bug list for now, but I'll prioritize the other problems first. If practical, when you post bugs, let me know if
they
 are showstoppers for your work or not. Thanks, -Walter
Dec 22 2002
parent "Walter" <walter digitalmars.com> writes:
Of course!

"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:au5a23$1q33$1 digitaldaemon.com...
 I presume that goes for all of us, yes?

 Matthew

 "Walter" <walter digitalmars.com> wrote in message
 news:au4toe$1hl3$1 digitaldaemon.com...
 "Christof Meerwald" <cmeerw web.de> wrote in message
 news:au4cno$166n$1 digitaldaemon.com...
 BTW, the example is not from Boost. It's inspired by some code from
omniORB,
 but it's not causing any real trouble as most other compilers also get
it
 wrong (including gcc 3.0) - but I am still hoping that I am right...
Ok. I'll keep it on the active bug list for now, but I'll prioritize the other problems first. If practical, when you post bugs, let me know if
they
 are showstoppers for your work or not. Thanks, -Walter
Dec 22 2002
prev sibling parent reply "Robert M. Münch" <robert.muench robertmuench.de> writes:
"Walter" <walter digitalmars.com> schrieb im Newsbeitrag
news:au4toe$1hl3$1 digitaldaemon.com...

 Ok. I'll keep it on the active bug list for now
Walter, how do you keep track of bugs and do you use a tool for this? Robert
Dec 23 2002
parent "Walter" <walter digitalmars.com> writes:
"Robert M. Münch" <robert.muench robertmuench.de> wrote in message
news:au6tij$2v32$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> schrieb im Newsbeitrag
 news:au4toe$1hl3$1 digitaldaemon.com...
 Ok. I'll keep it on the active bug list for now
Walter, how do you keep track of bugs and do you use a tool for this?
Robert Oh, I just move them around between folders in Outlook.
Dec 23 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
namespace ns
{
struct B
{ };

struct A
{
  A(B b);
};
}

ns::A::A(B b)
// Error: ')' expected to close function parameter list with
{
}


int main()
{
  ns::B b;
  ns::A a(b);

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de
Dec 16 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
namespace ns
{
const int A = 0;

struct A
{
  A()
  // Error: no constructor allowed for class 'A'
  { }
};

struct B
{ };
}

struct C
  : ns::B
{
  C()
    : B()
  // Error: 'B' is not a member of struct 'C'
  { }
};


int main()
{
  C c;

  return 0;
}


See 9 Classes [class], paragraph 2, of the C++ standard.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 21 2002
prev sibling next sibling parent Christof Meerwald <cmeerw web.de> writes:
namespace ns
{
void f();
void g();
}

void ns::f()
{ }

void ns::g()
{
  f();
  // Error: undefined identifier 'f'
}


int main()
{
  ns::g();

  return 0;
}


See 3.4.1 Unqualified name lookup [basic.lookup.unqual], paragraph 6, of the
C++ standard.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 21 2002
prev sibling parent reply Christof Meerwald <cmeerw web.de> writes:
void f();

namespace ns
{
using ::f;
}

using ns::f;

int main()
{
  f();
  // Error: ambiguous reference to symbol

  return 0;
}


It's the same function (see 7.3.3 The using declaration [namespace.udecl],
paragraph 10 and 3.3 Declarative regions and scopes [basic.scope], paragraph
4).


Workaround is simple, so it's low priority.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Jan 01 2003
parent Christof Meerwald <cmeerw web.de> writes:
Quite similar to the previous one:

void f();

namespace ns
{
using ::f;
using ::f;
}

int main()
{
  ns::f();

  return 0;
}


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Jan 01 2003