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]
Other format: [Raw text]

[Bug other/16678] New: warning: suggest parentheses around assignment used as truth value


Compiling the code snippet

========================================
#include<iostream>

void foo(std::istream &s)
{
    int i;
    s >> i;
}
========================================

with "g++ -O3 -Wall" on mainline, I get the warning:

/Work/reichelt/GCC/FARM/gcc-3.5-20040722/bin/../lib/gcc/i686-pc-linux-gnu/3.5.0/../../../../include/c++/3.5.0/bits/locale_facets.tcc:
In member function `_InIter std::num_get<_CharT,
_InIter>::_M_extract_int(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&,
_ValueT&) const [with _ValueT = long int, _CharT = char, _InIter =
std::istreambuf_iterator<char, std::char_traits<char> >]':
/Work/reichelt/GCC/FARM/gcc-3.5-20040722/bin/../lib/gcc/i686-pc-linux-gnu/3.5.0/../../../../include/c++/3.5.0/bits/locale_facets.tcc:693:  
instantiated from `_InIter std::num_get<_CharT, _InIter>::do_get(_InIter,
_InIter, std::ios_base&, std::_Ios_Iostate&, long int&) const [with _CharT =
char, _InIter = std::istreambuf_iterator<char, std::char_traits<char> >]'
/Work/reichelt/GCC/FARM/gcc-3.5-20040722/bin/../lib/gcc/i686-pc-linux-gnu/3.5.0/../../../../include/c++/3.5.0/bits/locale_facets.h:2014:  
instantiated from `_InIter std::num_get<_CharT, _InIter>::get(_InIter, _InIter,
std::ios_base&, std::_Ios_Iostate&, long int&) const [with _CharT = char,
_InIter = std::istreambuf_iterator<char, std::char_traits<char> >]'
/Work/reichelt/GCC/FARM/gcc-3.5-20040722/bin/../lib/gcc/i686-pc-linux-gnu/3.5.0/../../../../include/c++/3.5.0/bits/istream.tcc:195:  
instantiated from `std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char,
_Traits = std::char_traits<char>]'
bug.cc:6:   instantiated from here
/Work/reichelt/GCC/FARM/gcc-3.5-20040722/bin/../lib/gcc/i686-pc-linux-gnu/3.5.0/../../../../include/c++/3.5.0/bits/locale_facets.tcc:537:
warning: suggest parentheses around assignment used as truth value
/Work/reichelt/GCC/FARM/gcc-3.5-20040722/bin/../lib/gcc/i686-pc-linux-gnu/3.5.0/../../../../include/c++/3.5.0/bits/locale_facets.tcc:580:
warning: suggest parentheses around assignment used as truth value

In fact line 580 in locale_facets.tcc reads:
            else if (__q = __traits_type::find(__lit_zero, __len, __c))

Grepping with the command
  egrep -nH "if \([_a-zA-Z0-9]+ = "
through mainline's sources there some more instances of such deprecated coding:

gcc/fixinc/procopen.c:95:  if (pz_cmd = *pp_args,
gcc/local-alloc.c:1359:           if (r1 = XEXP (note, 0), REG_P (r1)
gcc/tlink.c:605:      else if (p = strchr (oldq, '"'), p)
libjava/java/lang/dtoa.c:325:      if (j = 11 - hi0bits (word0 (d2) &
Frac_mask))
libjava/java/lang/mprec.c:388:      if (y = *xb++)
libjava/java/lang/mprec.c:815:  if (y = d1)
libjava/java/lang/mprec.c:817:      if (k = lo0bits (&y))
libstdc++-v3/include/bits/locale_facets.tcc:371:          else if (__q =
__traits_type::find(__lit_zero, 10, __c))
libstdc++-v3/include/bits/locale_facets.tcc:537:            else if (__q =
__traits_type::find(__lit_zero, __len, __c))
libstdc++-v3/include/bits/locale_facets.tcc:580:            else if (__q =
__traits_type::find(__lit_zero, __len, __c))
libstdc++-v3/include/bits/locale_facets.tcc:1123:      if (__p =
char_traits<_CharT>::find(__ws, __len, __cdec))
libstdc++-v3/include/bits/locale_facets.tcc:1359:             if (__q =
__traits_type::find(__lit_zero, 10, *__beg))

This should be fixed.

-- 
           Summary: warning: suggest parentheses around assignment used as
                    truth value
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: minor
          Priority: P2
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16678


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