This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug report



To whom this may concern,

$uname -a
Linux atlas22 2.0.35 #1 Wed Nov 25 15:50:56 CET 1998 i686 unknown

$g++ --version
2.95.2

$more problem.cxx
#include <assert.h>

template< class TPtr >
class Ptr {
public:
  Ptr( TPtr* ptr = 0 ) : _ptr( ptr ) {}
  operator bool() const;
private:
  TPtr* _ptr;
};

template< class TPtr >
inline Ptr< TPtr >::operator bool() const {
   return _ptr;
}

void func( const Ptr< int >& r ) {
   assert( static_cast< bool >( r ) );
}

int main() {
   int i = 1;
   Ptr< int > pi( &i );
   func( pi );
   return 0;
}

$g++ problem.cxx
problem.cxx: In function `void func(const Ptr<int> &)':
problem.cxx:18: static_cast from `const Ptr<int>' to `bool'

Please note that the problem only occurs if:
1) the Ptr class is a template,
2) the function takes a reference and
3) the reference is passed as a function argument (taking a
   reference in main and then asserting works fine)

Best regards,
         Wim Lavrijsen



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]