aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2024-04-10 15:12:26 -0400
committerJason Merrill <jason@redhat.com>2024-04-12 15:34:29 -0400
commitdf7bfdb7dbf2d46aa5768a0280d4dcfcc868b7f9 (patch)
tree963ecde0b9cf6971d1cd577d9aacfc03ee3305a3 /gcc/doc
parentd435571b54b02946c97b5b24f20e5a7058fd96a1 (diff)
downloadgcc-df7bfdb7dbf2d46aa5768a0280d4dcfcc868b7f9.zip
gcc-df7bfdb7dbf2d46aa5768a0280d4dcfcc868b7f9.tar.gz
gcc-df7bfdb7dbf2d46aa5768a0280d4dcfcc868b7f9.tar.bz2
c++: reference cast, conversion fn [PR113141]
The second testcase in 113141 is a separate issue: we first decide that the conversion is ill-formed, but then when recalculating the special c_cast_p handling makes us think it's OK. We don't want that, it should continue to fall back to the reinterpret_cast interpretation. And while we're here, let's warn that we're not using the conversion function. Note that the standard seems to say that in this case we should treat (Matrix &) as const_cast<Matrix &>(static_cast<const Matrix &>(X)), which would use the conversion operator, but that doesn't match existing practice, so let's resolve that another day. I've raised this issue with CWG; at the moment I lean toward never binding a temporary in a C-style cast to reference type, which would also be a change from existing practice. PR c++/113141 gcc/c-family/ChangeLog: * c.opt: Add -Wcast-user-defined. gcc/ChangeLog: * doc/invoke.texi: Document -Wcast-user-defined. gcc/cp/ChangeLog: * call.cc (reference_binding): For an invalid cast, warn and don't recalculate. gcc/testsuite/ChangeLog: * g++.dg/conversion/ref12.C: New test. Co-authored-by: Patrick Palka <ppalka@redhat.com>
Diffstat (limited to 'gcc/doc')
-rw-r--r--gcc/doc/invoke.texi13
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 5d5e70c..e328558 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -9391,6 +9391,19 @@ In a cast involving pointer to member types this warning warns whenever
the type cast is changing the pointer to member type.
This warning is enabled by @option{-Wextra}.
+@opindex Wcast-user-defined
+@opindex Wno-cast-user-defined
+@item -Wcast-user-defined
+Warn when a cast to reference type does not involve a user-defined
+conversion that the programmer might expect to be called.
+
+@smallexample
+struct A @{ operator const int&(); @} a;
+auto r = (int&)a; // warning
+@end smallexample
+
+This warning is enabled by default.
+
@opindex Wwrite-strings
@opindex Wno-write-strings
@item -Wwrite-strings