https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107466
Bug ID: 107466 Summary: [12 Regression] invalid -Wnarrowing error Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: littlefox+gcc-bugzi...@lf-net.org Target Milestone: --- Created attachment 53797 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53797&action=edit Code triggering the error Hi, the attached code (and Godbolt[1]) fails in gcc 12+ with an -Wnarrowing error in a stdlibc++ template instantiated with an uint16_t and apparently trying to work with a 2^31: /opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/bits/random.tcc:545:9: error: narrowing conversion of '2147483563' from 'unsigned int' to 'short unsigned int' [-Wnarrowing] 545 | __lcg(__value == 0u ? default_seed : __value); The code works fine in 11.3 and clang (14) and since it also works in clang using libstdc++ 12.2, this error is probably in gcc itself and not in libstdc++. Tested this on my machine (debian testing), where it broke after a some system updates where installed - including a gcc update. Then tested this in Godbolt to check compiler versions and other configurations and asked in libera.chat/#c++ for others to verify if my code makes sense - which it seems to do. Best, Mara [1] Godbolt link: https://godbolt.org/z/sj18Mv5j9