Bug 92219 - -Wconversion generates a false warning for modulo expression when the modulus has smaller type
Summary: -Wconversion generates a false warning for modulo expression when the modulus...
Status: RESOLVED DUPLICATE of bug 92220
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 9.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-25 04:50 UTC by John Simon
Modified: 2019-10-25 08:28 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Simon 2019-10-25 04:50:01 UTC
```
[]$ gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto
Thread model: posix
gcc version 9.2.0 (GCC) 

[]$ cat a.c
int f(long long a,int b){
	return a%b;
}

[]$ gcc -Wall -Wconversion a.c -c
a.c: In function ‘f’:
a.c:2:10: warning: conversion from ‘long long int’ to ‘int’ may change value [-Wconversion]
    2 |  return a%b;
      |         ~^~
```

The specification for `-Wconversion` is "Warn for implicit conversions that may alter a value.". In this case the result is guaranteed to be convertible to the type of `b` (`int`) without changing the value.
Comment 1 Richard Biener 2019-10-25 08:28:27 UTC
.

*** This bug has been marked as a duplicate of bug 92220 ***