This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Potentially uninitialized variable warning in basic_ios.tcc
- From: Wolfgang Bangerth <wolfgang dot bangerth at iwr dot uni-heidelberg dot de>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 7 Feb 2002 14:25:08 +0100 (MET)
- Subject: Potentially uninitialized variable warning in basic_ios.tcc
Hi there,
testing a recent gcc CVS, I got following warning:
/home/people/wolf/Config/i686-pc-linux-gnu/include/g++-v3/bits/basic_ios.tcc:105:
warning: `char __ret' might be used uninitialized in this function
Indeed, this function (which was modified last Jan 25th), has the
following content:
template<typename _CharT, typename _Traits>
_CharT
basic_ios<_CharT, _Traits>::widen(char __c) const
{
char_type __ret;
if (_M_check_facet(_M_ios_fctype))
__ret = _M_ios_fctype->widen(__c);
return __ret;
}
(The same holds for the function basic_ios::narrow above that.) Was this
intended? Since _M_check_facet returns "true" or throws a bad_cast
exception, the only valid exit path is indeed by initializing the
variable, but in order to calm down the warning, I'd like to propose the
attached patch.
Regards
Wolfgang
-------------------------------------------------------------------------
Wolfgang Bangerth email: wolfgang.bangerth@iwr.uni-heidelberg.de
www: http://gaia.iwr.uni-heidelberg.de/~wolf
Index: basic_ios.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_ios.tcc,v
retrieving revision 1.8
diff -c -r1.8 basic_ios.tcc
*** basic_ios.tcc 2002/01/25 06:36:31 1.8
--- basic_ios.tcc 2002/02/07 13:23:36
***************
*** 91,111 ****
template<typename _CharT, typename _Traits>
char
basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
! {
! char __ret;
if (_M_check_facet(_M_ios_fctype))
! __ret = _M_ios_fctype->narrow(__c, __dfault);
! return __ret;
}
template<typename _CharT, typename _Traits>
_CharT
basic_ios<_CharT, _Traits>::widen(char __c) const
{
! char_type __ret;
if (_M_check_facet(_M_ios_fctype))
! __ret = _M_ios_fctype->widen(__c);
! return __ret;
}
// Locales:
--- 91,115 ----
template<typename _CharT, typename _Traits>
char
basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
! {
! // return narrowed value if facet is valid...
if (_M_check_facet(_M_ios_fctype))
! return _M_ios_fctype->narrow(__c, __dfault);
!
! // ...otherwise return some value to calm down compiler warnings
! return __dfault;
}
template<typename _CharT, typename _Traits>
_CharT
basic_ios<_CharT, _Traits>::widen(char __c) const
{
! // return narrowed value if facet is valid...
if (_M_check_facet(_M_ios_fctype))
! return _M_ios_fctype->widen(__c);
!
! // ...otherwise return some value to calm down compiler warnings
! return _CharT();
}
// Locales: