Thread: [orbitcpp-list] warnings
Status: Beta
Brought to you by:
philipd
From: Laszlo M. <las...@et...> - 2000-08-18 09:09:14
|
Hi Folks! Some days ago I tried to investigate why gcc gives tons of warnings during compilation of orbitc++ generated stuff. After I found the main cause (those const/non const cast operators) I looked at some other orbs how they solve this problem. I found special ifdefs in both mico and omniorb, unfortunately none of those solutions were 100% perfect. Anyway when I do something similar for orbitc++, I was not able to compile everything :( And unfortunately gcc 2.96 issues these warnings too :( But there is another kind of warnings, which is caused by this stuff in pass_stubs.cc: void IDLPassStubs::doInterface(IDLInterface &iface) [...] // make cast operators for all mi base classes IDLInterface::BaseList::const_iterator first = iface.m_all_mi_bases.begin(),last = iface.m_all_mi_bases.end(); while (first != last) { m_header << indent << "operator " << (*first)->getQualifiedCPPIdentifier() << " &() {" << endl; m_header << ++indent << "return *" << (*first)->getQualifiedCPPCast("this") << ';' << endl; m_header << --indent << '}' << endl; first++; } Here gcc says, that there is no point to provide operator Base&() for the derived classes, because it won't execute them, but do the right thing itself ;) So I guess, this code could be safely removed. Laszlo |
From: Phil D. <ph...@us...> - 2000-08-20 14:58:35
|
Laszlo Molnar writes: > Hi Folks! Hi Laslo, > > Some days ago I tried to investigate why gcc gives tons of warnings > during compilation of orbitc++ generated stuff. After I found the main > cause (those const/non const cast operators) I looked at some other > orbs how they solve this problem. I found special ifdefs in both mico > and omniorb, unfortunately none of those solutions were 100% perfect. > Anyway when I do something similar for orbitc++, I was not able to > compile everything :( > > And unfortunately gcc 2.96 issues these warnings too :( > I need to do some work in this area. Any info on what sort of hacks mico and omniorb use (or where to look for them) would be very helpful. > But there is another kind of warnings, which is caused by this > stuff in pass_stubs.cc: > [example snipped] > Here gcc says, that there is no point to provide > > operator Base&() > > for the derived classes, because it won't execute them, but do the > right thing itself ;) > > So I guess, this code could be safely removed. > Hmmm - I suspect not. The thing is that we aren't using real C++ objects, we're casting ORBit C objects into C++ ones, and using these cast operators to insure that the compiler doesn't try to do smart thunking in the case of multiple inheritance downcasts. This provides a good speed increase over wrapping the C objects in C++ ones. Does the 'everything' test in orbitcpp CVS work with gcc 2.96? Thanks for your work, Cheers, Phil. |
From: Laszlo M. <las...@et...> - 2000-08-21 09:13:35
|
> I need to do some work in this area. Any info on what sort of hacks > mico and omniorb use (or where to look for them) would be very > helpful. OK, mico does this in include/var.h: template<class T> class ObjVar { // [...] // g++ const overload problem #ifdef HAVE_CONST_OVERLOAD operator T*() const { return _ptr; } operator T*&() { check(); return _ptr; } #else operator T*&() const { ((ObjVar<T>*)this)->check(); return (T*&)_ptr; } #endif } and here is the test from its aclocal.m4 AC_DEFUN(AC_CONST_OVERLOAD, [AC_MSG_CHECKING(for const overload) AC_CACHE_VAL(ac_cv_have_const_overload, [ac_cv_tmp_old_cxxflags="$CXXFLAGS" if test X"$GXX" = Xyes; then CXXFLAGS="-Werror $CXXFLAGS" fi AC_TRY_COMPILE_GLOBAL(,[ struct S { int *i; operator const int *() const { return i; } operator int *&() { return i; } operator const int &() const { return *i; } operator int &() { return *i; } }; void bar (const int &, int &, const int *, int *, int *&); void foo (S &s, const S &cs) { int i = s; i = cs; i = *s; i = *cs; bar (s, s, s, s, s); bar (cs, s, cs, s, s); } ], eval "ac_cv_have_const_overload=yes", eval "ac_cv_have_const_overload=no",) CXXFLAGS=$ac_cv_tmp_old_cxxflags ]) > > operator Base&() > > So I guess, this code could be safely removed. > Hmmm - I suspect not. The thing is that we aren't using real C++ > objects, we're casting ORBit C objects into C++ ones, and using these > cast operators to insure that the compiler doesn't try to do smart > thunking in the case of multiple inheritance downcasts. This provides > a good speed increase over wrapping the C objects in C++ ones. The problem is that as the warning says, gcc will NOT USE that operator when it does the casting. Consider this example: struct Base {}; Base dummy; struct Derived : public Base { operator Base &() { return dummy; } }; gcc gives: x.cc:8: warning: conversion to a reference to a base class will never use a type conversion operator And gcc is right, because it's totally silly what I'm doing. I have no idea, why this is only a warning, IMHO it should be an error. > Does the 'everything' test in orbitcpp CVS work with gcc 2.96? Well, I just checked whether this const/non const warning is still there, and didn't compile anything useful (I doubt I could - 2.96 is not binary compatible with my libraries). Laszlo |