[PATCH] D125402: [clang][diag] warn if function returns class type by-const-value

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 27 01:26:00 PST 2023


cor3ntin added a comment.

This has been sitting in the queue for a while, sorry about that.
I think this makes sense in its current iteration, with the warning always on. Have you tried to build a large project like chrome with it?



================
Comment at: clang/lib/Sema/SemaChecking.cpp:16843
+
+  RHSExpr = RHSExpr->IgnoreImplicit();
+
----------------
Maybe we should ignore parentheses too?


================
Comment at: clang/lib/Sema/SemaChecking.cpp:16850-16856
+  const Decl *CD = CE->getCalleeDecl();
+  if (!CD)
+    return;
+
+  const FunctionDecl *FD = dyn_cast<const FunctionDecl>(CD);
+  if (!FD)
+    return;
----------------
you can use `CE->getDirectCallee()` here


================
Comment at: clang/lib/Sema/SemaChecking.cpp:16874
+    const SourceRange ReturnTypeLoc = FD->getReturnTypeSourceRange();
+    Diag(ReturnTypeLoc.getBegin(), diag::warn_pessimizing_return_by_const);
+    Diag(OpLoc, diag::note_pessimizing_return_by_const)
----------------
I think a fixit to remove the const would be nice.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125402/new/

https://reviews.llvm.org/D125402



More information about the cfe-commits mailing list