[clang] [clang] Generate note on declaration for nodiscard-related attributes (PR #112289)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 15 09:51:07 PDT 2024
================
@@ -302,27 +307,43 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
if (const Decl *FD = CE->getCalleeDecl()) {
if (ShouldSuppress)
return;
- if (FD->hasAttr<PureAttr>()) {
- Diag(Loc, diag::warn_unused_call) << R1 << R2 << "pure";
- return;
- }
- if (FD->hasAttr<ConstAttr>()) {
- Diag(Loc, diag::warn_unused_call) << R1 << R2 << "const";
+
+ const InheritableAttr *A = nullptr;
+ if (const auto *PA = FD->getAttr<PureAttr>())
+ A = PA;
+ else if (const auto *CA = FD->getAttr<ConstAttr>())
+ A = CA;
+
+ if (A) {
+ StringRef type = (isa<PureAttr>(A) ? "pure" : "const");
+ Diag(Loc, diag::warn_unused_call) << R1 << R2 << type;
+ if (const auto *ND = dyn_cast<NamedDecl>(OffendingDecl)) {
+ if (!ND->getIdentifier()->getBuiltinID())
----------------
erichkeane wrote:
I still didn't get the justification for skipping if this is a builtin? It seems sensible to do so, even if the source location is a builtin.
https://github.com/llvm/llvm-project/pull/112289
More information about the cfe-commits
mailing list