[PATCH] D148505: Allow `__attribute__((warn_unused))` on individual constructors

Stephan Bergmann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 17 02:09:57 PDT 2023


sberg created this revision.
sberg added a reviewer: erichkeane.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
sberg requested review of this revision.
Herald added a project: clang.

This takes inspiration from the standard `nodiscard` attribute, which can also be declared on individual constructors.  (I have used this change locally for about a year on the LibreOffice code base, marking various compilers as `warn_unused`, without any positive or negative effects.  Until I happened to notice an additional constructor that would benefit from `warn_unused`, and which found about 20 unused variables across the LibreOffice code base, see e.g., https://git.libreoffice.org/core/+/7cdbe504ff3b59d3aec1b1e86caf7f24223dce72%5E! "Fix what looks like copy/paste typos".)

(The changes in `clang/test/Misc/pragma-attribute-strict-subjects.c`, `clang/test/Parser/pragma-attribute.cpp`, and `clang/test/Sema/pragma-attribute-strict-subjects.c` are necessary to make those tests not fail after adding `SubRuleForCXXConstructor` to `SubjectMatcherForFunction` in `clang/include/clang/Basic/Attr.td`.  It appears that the exact diagnostic output that is generated is somewhat brittle, depending on implementation details.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148505

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DeclNodes.td
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Misc/pragma-attribute-strict-subjects.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Sema/pragma-attribute-strict-subjects.c
  clang/test/SemaCXX/warn-unused-attribute.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148505.514142.patch
Type: text/x-patch
Size: 9236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230417/671ef909/attachment.bin>


More information about the cfe-commits mailing list