Bug 93652 - -Wconversion gives false warning with bitwise operations on reference types returned from function
Summary: -Wconversion gives false warning with bitwise operations on reference types r...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.2.0
: P3 normal
Target Milestone: 10.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2020-02-10 13:57 UTC by John Simon
Modified: 2021-07-20 17:47 UTC (History)
2 users (show)

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 2020-02-10 13:57:30 UTC
```
[]$ /bin/g++ -v
Using built-in specs.
COLLECT_GCC=/bin/g++
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++,d --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 gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC) 
[]$ cat a.cpp
char x,y;
char& f(){ return x; }
char& g(){ return y; }
void h(){ f()^=g(); }
[]$ /bin/g++ -Wconversion -c a.cpp 
a.cpp: In function ‘void h()’:
a.cpp:4:18: warning: conversion from ‘int’ to ‘char’ may change value [-Wconversion]
    4 | void h(){ f()^=g(); }
      |                  ^

```

Similar to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38522, but this only happens with reference returned from functions. Local reference created in the function or local variable does not raise the bug.
Comment 1 Tomasz Konojacki 2021-07-20 17:26:40 UTC
This was fixed in gcc 10, I think it can be closed.
Comment 2 Andrew Pinski 2021-07-20 17:31:41 UTC
Fixed.
Comment 3 Jonathan Wakely 2021-07-20 17:47:28 UTC
Fixed by r10-7344:
    c++: Handle COMPOUND_EXPRs in get_narrower and warnings_for_convert_and_check [PR91993]