diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2021-05-17 10:53:56 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2021-05-17 21:04:31 +0100 |
commit | 5d93261bc03c9c6891ccd8c77ab22b2a09971905 (patch) | |
tree | 5c51a0e81baf9fe78daa93a319f38b5682fb718b /gcc/cp | |
parent | 09867aa0ef7568012650395189b735f9a34cf9b5 (diff) | |
download | gcc-5d93261bc03c9c6891ccd8c77ab22b2a09971905.zip gcc-5d93261bc03c9c6891ccd8c77ab22b2a09971905.tar.gz gcc-5d93261bc03c9c6891ccd8c77ab22b2a09971905.tar.bz2 |
c++: Fix diagnostic for binding lvalue reference to volatile rvalue [PR 100635]
The current diagnostic assumes the reference binding fails because the
reference is non-const, but it can also fail if the rvalue is volatile.
Use the current diagnostic for non-const cases, and a modified
diagnostic otherwise.
gcc/cp/ChangeLog:
PR c++/100635
* call.c (convert_like_internal): Print different diagnostic if
the lvalue reference is const.
gcc/testsuite/ChangeLog:
* g++.dg/conversion/pr100635.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/call.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f07e09a..1e2d1d4 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7900,9 +7900,13 @@ convert_like_internal (conversion *convs, tree expr, tree fn, int argnum, "type %qH to a value of type %qI", totype, next->type); } - else + else if (!CP_TYPE_CONST_P (TREE_TYPE (ref_type))) error_at (loc, "cannot bind non-const lvalue reference of " "type %qH to an rvalue of type %qI", totype, extype); + else // extype is volatile + error_at (loc, "cannot bind lvalue reference of type " + "%qH to an rvalue of type %qI", totype, + extype); } else if (!reference_compatible_p (TREE_TYPE (totype), extype)) { |