public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-849] c++: Fix diagnostic for binding lvalue reference to volatile rvalue [PR 100635]
@ 2021-05-17 20:04 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-05-17 20:04 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5d93261bc03c9c6891ccd8c77ab22b2a09971905

commit r12-849-g5d93261bc03c9c6891ccd8c77ab22b2a09971905
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon May 17 10:53:56 2021 +0100

    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.

Diff:
---
 gcc/cp/call.c                              |  6 +++++-
 gcc/testsuite/g++.dg/conversion/pr100635.C | 12 ++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index f07e09a36d1..1e2d1d43184 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))
 	      {
diff --git a/gcc/testsuite/g++.dg/conversion/pr100635.C b/gcc/testsuite/g++.dg/conversion/pr100635.C
new file mode 100644
index 00000000000..58412152238
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/pr100635.C
@@ -0,0 +1,12 @@
+// PR c++/100635
+// { dg-do compile }
+// { dg-additional-options "-Wno-volatile" { target c++2a } }
+
+struct S { };
+volatile S v();
+const volatile S& svol = v(); // { dg-error "cannot bind lvalue reference of type 'const volatile S&' to an rvalue of type 'volatile S'" }
+
+#if __cplusplus >= 201103L
+volatile int&& declvol();
+const volatile int& voli = declvol(); // { dg-error "cannot bind lvalue reference of type 'const volatile int&' to an rvalue of type 'volatile int'" "" { target c++11} }
+#endif


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-17 20:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 20:04 [gcc r12-849] c++: Fix diagnostic for binding lvalue reference to volatile rvalue [PR 100635] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).