Re: [orbitcpp-list] warnings
Status: Beta
Brought to you by:
philipd
|
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
|