This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77370] New: missing -Wignored-qualiifiers on a bogus const reference
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 24 Aug 2016 17:12:07 +0000
- Subject: [Bug c++/77370] New: missing -Wignored-qualiifiers on a bogus const reference
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77370
Bug ID: 77370
Summary: missing -Wignored-qualiifiers on a bogus const
reference
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
GCC rejects the program below because it tries to initialize the non-const
reference object cr with a temporary, but it doesn't diagnose the declaration
of the reference type CR where it disregards the const qualifier. In contrast,
Clang diagnoses both. GCC could be improved by doing the same.
$ (set -x && cat z.C && /build/gcc-trunk-svn/gcc/xgcc -B
/build/gcc-trunk-svn/gcc -Wall -Wextra -Wpedantic z.C;
/build/llvm-trunk/bin/clang -S -Wall z.C)
+ cat z.C
typedef char& R;
typedef const R CR;
char c;
R r = c;
CR cr = 'b';
+ /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -Wall -Wextra
-Wpedantic z.C
z.C:6:9: error: cannot bind non-const lvalue reference of type ‘CR {aka char&}’
to an rvalue of type ‘char’
CR cr = 'b';
^~~
+ /build/llvm-trunk/bin/clang -S -Wall z.C
z.C:2:9: warning: 'const' qualifier on reference type 'R' (aka 'char &') has no
effect [-Wignored-qualifiers]
typedef const R CR;
^~~~~~
z.C:6:4: error: non-const lvalue reference to type 'char' cannot bind to a
temporary of type 'char'
CR cr = 'b';
^ ~~~
1 warning and 1 error generated.