gcc warns about the unused variable on line 3 below but not for the one on line
8. I would expect to see a warning in both cases.

$ cat -n z.cpp && g++ -O2 -Wunused z.cpp
     1  int main()
     2  {
     3      if (bool b = 1)
     4          return 0;
     5      else
     6          return 1;
     7
     8      if (const bool b = 1)
     9          return 0;
    10      else
    11          return 1;
    12  }
z.cpp: In function ‘int main()’:
z.cpp:3: warning: unused variable ‘b’


-- 
           Summary: missing -Wunused warning on a const variable in if
                    statement
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: msebor at gmail dot com
 GCC build triplet: all
  GCC host triplet: all
GCC target triplet: all


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

Reply via email to