https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80119

            Bug ID: 80119
           Summary: -Wmaybe-uninitialized wrongly flags the body of a
                    short-circuited if-clause
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: julian.pfeifle at upc dot edu
  Target Milestone: ---

Consider

#include <type_traits>

template <bool b>
void failing_function(std::integral_constant<bool, b>)
{
   int i;
   if (b && (i=4)) {
      ++i;
   } 
}

int main (void)
{
   failing_function(std::false_type());
}

Compiling with -Wall gives 

test.cc: In function `void failing_function(std::integral_constant<bool, __v>)
[with bool b = false]`:
test.cc:8:7: error: `i` may be used uninitialized in this function
[-Werror=maybe-uninitialized]
       ++i;
       ^~

even though b is false, for which reason the body of the if-clause shouldn't
even be considered.

Calling failing_function(std::true_type()) compiles, as expected.

The `i=4` originally was a more complicated function call.

The error is important because it precludes compiling with -Werror.

gcc versions up to 6.1.0 handled this fine, I don't know about 6.2.*.

Reply via email to