[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 14 01:17:08 PDT 2024


================
@@ -387,9 +388,16 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
   // Do not diagnose use of a comma operator in a SFINAE context because the
   // type of the left operand could be used for SFINAE, so technically it is
   // *used*.
-  if (DiagID != diag::warn_unused_comma_left_operand || !isSFINAEContext())
-    DiagIfReachable(Loc, S ? llvm::ArrayRef(S) : std::nullopt,
-                    PDiag(DiagID) << R1 << R2);
+  if (DiagID == diag::warn_unused_comma_left_operand && isSFINAEContext())
+    return;
+
+  // Don't diagnose discarded left of dot in static class member access
+  // because its type is "used" to determine the class to access
+  if (OrigDiagID == diag::warn_discarded_class_member_access)
+    return;
----------------
Sirraide wrote:

> I think that this warning shouldn't be applied when the thing that is discarded is/was dependently typed.

Yeah, I think that makes sense.

> existing warnings about `[[nodiscard]]` values being discarded in new positions.

That’s what I would expect, so that also makes sense.

https://github.com/llvm/llvm-project/pull/95112


More information about the cfe-commits mailing list