c++.beta - [8.50.1n] another bug
- Pavel Vozenilek (26/26) Dec 01 2006 This code fails on 8.50.1n while it works with Comeau
- Walter Bright (1/1) Dec 01 2006 Thanks!
- Pavel Vozenilek (5/25) Dec 12 2006 I'd checked the code against 8.50.2 beta.
- Walter Bright (2/34) Dec 12 2006 That's because there's no += defined for point.
- Pavel Vozenilek (6/40) Dec 13 2006 Hmm. The operator is not called so it may not matter
- Pavel Vozenilek (3/45) Dec 13 2006 Borland C++ 6.4 compiles the snippet as well.
- Walter Bright (2/7) Dec 13 2006 Could you put a syntax error in the function and see if it complains?
- Pavel Vozenilek (13/20) Dec 13 2006 With VC++ 2005 syntax error within the unused function
- Walter Bright (2/13) Dec 14 2006 But a friend is not a member.
- Pavel Vozenilek (16/29) Dec 14 2006 Actually, DMC may be right
- Walter Bright (3/35) Dec 14 2006 That's a reasonable idea.
- Walter Bright (1/1) Dec 14 2006 I'm asking the question on comp.lang.c++.moderated. We'll see!
- Walter Bright (6/7) Dec 23 2006 As James Kanze explained on comp.lang.c++.moderated, DMC++ is correct
- Pavel Vozenilek (23/23) Dec 13 2006 Here's another snippet showing the problem (extracted from
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
----------------------- 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
Pavel Vozenilek wrote:That's because there's no += defined for point.----------------------- 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
Dec 12 2006
"Walter Bright" wrotePavel 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. /PavelThat's because there's no += defined for point.----------------------- 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
Dec 13 2006
"Pavel Vozenilek" wrote"Walter Bright" wroteBorland C++ 6.4 compiles the snippet as well. /PavelPavel 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. /PavelThat's because there's no += defined for point.----------------------- 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
Dec 13 2006
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
"Walter Bright" wrote:Pavel Vozenilek wrote: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 /PavelHmm. 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
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/0cb95f20593b7777But a friend is not a member.
Dec 14 2006
"Walter Bright" wrote:Pavel Vozenilek wrote: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. /PavelI 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/0cb95f20593b7777But a friend is not a member.
Dec 14 2006
Pavel Vozenilek wrote:"Walter Bright" wrote:Does Boost have a bug report submittal process?Pavel Vozenilek wrote: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]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/0cb95f20593b7777But a friend is not a member.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
I'm asking the question on comp.lang.c++.moderated. We'll see!
Dec 14 2006
Pavel Vozenilek wrote:Actually, DMC may be rightAs 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
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