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

            Bug ID: 115695
           Summary: spurious warning for -Wsign-compare with c++
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mtasaka at fedoraproject dot org
  Target Milestone: ---

With Fedora's gcc:

```
gcc --version
gcc (GCC) 14.1.1 20240620 (Red Hat 14.1.1-6)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

```
$ cat foo.cc 
#include <iostream>
#include <cstdint>

int main() {
        int16_t a = 0;
        std::cout << ((uint32_t)a * sizeof(int16_t)) << std::endl;
}
$ g++ -Wall -Wextra -Wsign-conversion -o foo foo.cc
foo.cc: In function ‘int main()’:
foo.cc:6:23: warning: conversion to ‘long unsigned int’ from ‘uint32_t’ {aka
‘unsigned int’} may change the sign of the result [-Wsign-conversion]
    6 |         std::cout << ((uint32_t)a * sizeof(int16_t)) << std::endl;
      |                       ^~~~~~~~~~~

```

What is apparently confusing that the signness does not change, yet the warning
says this "may change the sign".
  • [Bug c++/115695] New: spurio... mtasaka at fedoraproject dot org via Gcc-bugs

Reply via email to