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

            Bug ID: 84488
           Summary: Incorrect "set but not used" warning for
                    static_cast<Enum>(double)
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: will at benfold dot com
  Target Milestone: ---

Test case:


int main ()
{
  enum Foo {};
  double one = 1.0;
  return static_cast<Foo>(one);
}


Output:


$ g++ -Wall -Wextra -o minimal minimal.cpp && (./minimal; echo $?)
minimal.cpp: In function ‘int main()’:
minimal.cpp:4:10: warning: variable ‘one’ set but not used
[-Wunused-but-set-variable]
     double one  = 1.0;
          ^
1


Changing the (one) to (+one) is enough to silence the warning.

Reply via email to