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

            Bug ID: 67866
           Summary: False positive -Wshift-count-overflow on template code
                    that checks for shift count overflow
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: scovich at gmail dot com
  Target Milestone: ---

The following code snippet evokes an obviously unhelpful warning:

==== bug.cpp ====
template <int M>
unsigned long int m()
{
    unsigned long int max_value = 1;
    if (M < 64)
        max_value = (max_value << M) - 1;
    else
        max_value = ~(max_value - 1);

    return max_value;
}

int main()
{
    m<64>();
}
=================

Output is:
g++-5.2 -Wshift-count-overflow bug.cpp -O3
bug.cpp: In instantiation of 'long unsigned int m() [with int M = 64]':
bug.cpp:14:11:   required from here
bug.cpp:6:32: warning: left shift count >= width of type
[-Wshift-count-overflow]
         max_value = (max_value << M) - 1;
                                ^

Reply via email to