www.digitalmars.com         C & C++   DMDScript  

c++.beta - [8.50.1n] another bug

reply "Pavel Vozenilek" <pavel_vozenilek yahoo.co.uk> writes:
This code fails on 8.50.1n while it works with Comeau
and looks well formed.

It is triggered by the friend declaration.

-----------------------
template <class T>
struct addable2
{
  friend T operator +( T lhs, const T& rhs ) { return lhs += rhs; }
};


template<class T>
struct addable : addable2<T>
{
};

template <class T>
class point  : addable< point<T> >
{
};

int main()
{
  point<int> ppp;
  return 0;
}
----------------------------

This bug manifests itself when
<boost/operators.hpp> is used.

/Pavel
Dec 01 2006
next sibling parent Walter Bright <newshound digitalmars.com> writes:
Thanks!
Dec 01 2006
prev sibling next sibling parent reply "Pavel Vozenilek" <pavel_vozenilek yahoo.co.uk> writes:
 -----------------------
 template <class T>
 struct addable2
 {
  friend T operator +( T lhs, const T& rhs ) { return lhs += rhs; }
 };


 template<class T>
 struct addable : addable2<T>
 {
 };

 template <class T>
 class point  : addable< point<T> >
 {
 };

 int main()
 {
  point<int> ppp;
  return 0;
 }
 ----------------------------
I'd checked the code against 8.50.2 beta. The previous version said something about unknown size of a structure, the current error message is a.cpp(4) : Error: undefined use of struct or union /Pavel
Dec 12 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
Pavel Vozenilek wrote:
 -----------------------
 template <class T>
 struct addable2
 {
  friend T operator +( T lhs, const T& rhs ) { return lhs += rhs; }
 };


 template<class T>
 struct addable : addable2<T>
 {
 };

 template <class T>
 class point  : addable< point<T> >
 {
 };

 int main()
 {
  point<int> ppp;
  return 0;
 }
 ----------------------------
I'd checked the code against 8.50.2 beta. The previous version said something about unknown size of a structure, the current error message is a.cpp(4) : Error: undefined use of struct or union
That's because there's no += defined for point.
Dec 12 2006
parent reply "Pavel Vozenilek" <pavel_vozenilek yahoo.co.uk> writes:
"Walter Bright"  wrote
 Pavel Vozenilek wrote:
 -----------------------
 template <class T>
 struct addable2
 {
  friend T operator +( T lhs, const T& rhs ) { return lhs += rhs; }
 };


 template<class T>
 struct addable : addable2<T>
 {
 };

 template <class T>
 class point  : addable< point<T> >
 {
 };

 int main()
 {
  point<int> ppp;
  return 0;
 }
 ----------------------------
I'd checked the code against 8.50.2 beta. The previous version said something about unknown size of a structure, the current error message is a.cpp(4) : Error: undefined use of struct or union
That's because there's no += defined for point.
Hmm. The operator is not called so it may not matter (opinion, I am no C++ lawyer). Comeau does not complain, neither does GCC 3.4.5 and VC++ 2005 also compiles it w/o problems. /Pavel
Dec 13 2006
next sibling parent "Pavel Vozenilek" <pavel_vozenilek yahoo.co.uk> writes:
"Pavel Vozenilek" wrote
 "Walter Bright"  wrote
 Pavel Vozenilek wrote:
 -----------------------
 template <class T>
 struct addable2
 {
  friend T operator +( T lhs, const T& rhs ) { return lhs += rhs; }
 };


 template<class T>
 struct addable : addable2<T>
 {
 };

 template <class T>
 class point  : addable< point<T> >
 {
 };

 int main()
 {
  point<int> ppp;
  return 0;
 }
 ----------------------------
I'd checked the code against 8.50.2 beta. The previous version said something about unknown size of a structure, the current error message is a.cpp(4) : Error: undefined use of struct or union
That's because there's no += defined for point.
Hmm. The operator is not called so it may not matter (opinion, I am no C++ lawyer). Comeau does not complain, neither does GCC 3.4.5 and VC++ 2005 also compiles it w/o problems. /Pavel
Borland C++ 6.4 compiles the snippet as well. /Pavel
Dec 13 2006
prev sibling parent reply Walter Bright <newshound digitalmars.com> writes:
Pavel Vozenilek wrote:
 Hmm. The operator is not called so it may not matter
 (opinion, I am no C++ lawyer).
 
 Comeau does not complain, neither does GCC 3.4.5
 and VC++ 2005 also compiles it w/o problems.
Could you put a syntax error in the function and see if it complains?
Dec 13 2006
parent reply "Pavel Vozenilek" <pavel_vozenilek yahoo.co.uk> writes:
"Walter Bright" wrote:

 Pavel Vozenilek wrote:
 Hmm. The operator is not called so it may not matter
 (opinion, I am no C++ lawyer).

 Comeau does not complain, neither does GCC 3.4.5
 and VC++ 2005 also compiles it w/o problems.
Could you put a syntax error in the function and see if it complains?
With VC++ 2005 syntax error within the unused function doesn't matter. GCC 3.4.5 fails with error about the syntax, Comeau also fails with the syntax. I read somewhere that unused members can be optionally syntactically checked but not semantically. A search on newsgroups seems to confirm this: Fergus Henderson: [T]he implementation _must not_ check [unused template member] (other than syntax checking)." (post from year 1995) http://groups.google.com/group/comp.std.c++/msg/0cb95f20593b7777 /Pavel
Dec 13 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
Pavel Vozenilek wrote:
 I read somewhere that unused members
 can be optionally syntactically checked but not semantically.
 
 
 A search on newsgroups seems to confirm this:
 
 Fergus Henderson: [T]he implementation _must not_ check
 [unused template member] (other than
 syntax checking)." (post from year 1995)
 
 http://groups.google.com/group/comp.std.c++/msg/0cb95f20593b7777
But a friend is not a member.
Dec 14 2006
parent reply "Pavel Vozenilek" <pavel_vozenilek yahoo.co.uk> writes:
"Walter Bright" wrote:
 Pavel Vozenilek wrote:
 I read somewhere that unused members
 can be optionally syntactically checked but not semantically.


 A search on newsgroups seems to confirm this:

 Fergus Henderson: [T]he implementation _must not_ check
 [unused template member] (other than
 syntax checking)." (post from year 1995)

 http://groups.google.com/group/comp.std.c++/msg/0cb95f20593b7777
But a friend is not a member.
Actually, DMC may be right (disclaimer - no language lawyer): Standard 14.5.3, section 3 says: 3. When a function is defined in a friend function declaration in a class template, the function is defined when the class template is first instantiated. The function is defined even if it is never used. [Note: if the function definition is illformed for a given specialization of the enclosing class template, the program is illformed even if the function is never used. -end note] Even if DMC is right perhaps a switch could be added to ignore this error as lot of Boost code depends on it and feels as rather un-natural limitation. /Pavel
Dec 14 2006
next sibling parent Walter Bright <newshound digitalmars.com> writes:
Pavel Vozenilek wrote:
 "Walter Bright" wrote:
 Pavel Vozenilek wrote:
 I read somewhere that unused members
 can be optionally syntactically checked but not semantically.


 A search on newsgroups seems to confirm this:

 Fergus Henderson: [T]he implementation _must not_ check
 [unused template member] (other than
 syntax checking)." (post from year 1995)

 http://groups.google.com/group/comp.std.c++/msg/0cb95f20593b7777
But a friend is not a member.
Actually, DMC may be right (disclaimer - no language lawyer): Standard 14.5.3, section 3 says: 3. When a function is defined in a friend function declaration in a class template, the function is defined when the class template is first instantiated. The function is defined even if it is never used. [Note: if the function definition is illformed for a given specialization of the enclosing class template, the program is illformed even if the function is never used. -end note]
Does Boost have a bug report submittal process?
 Even if DMC is right perhaps a switch could be added
 to ignore this error as lot of Boost code depends on it
 and feels as rather un-natural limitation.
That's a reasonable idea.
Dec 14 2006
prev sibling next sibling parent Walter Bright <newshound digitalmars.com> writes:
I'm asking the question on comp.lang.c++.moderated. We'll see!
Dec 14 2006
prev sibling parent Walter Bright <newshound digitalmars.com> writes:
Pavel Vozenilek wrote:
 Actually, DMC may be right
As James Kanze explained on comp.lang.c++.moderated, DMC++ is correct according to the Standard. However, nobody else does it that way, and the Standard is going to be changed to make such code correct. There's no use in swimming against the tide, so I'll change DMC++ to conform to common practice.
Dec 23 2006
prev sibling parent "Pavel Vozenilek" <pavel_vozenilek yahoo.co.uk> writes:
Here's another snippet showing the problem (extracted from 
<boost/operators.hpp>):

---------a.cpp---------------
template <class T>
struct decrementable
{
  friend T operator--(decrementable& x, int)
  {
    decrementable_type nrv(x);
    --x;
    return nrv;
  }
private:
  typedef T decrementable_type;
};



int main( int , char * [] )
{
  decrementable<int> a;
  return 0;
}
---------------------

Comeau does compile it.

/Pavel
Dec 13 2006