[PATCH] D129835: [clang] adds a discardable attribute

Christopher Di Bella via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 14 23:24:35 PDT 2022


cjdb created this revision.
cjdb added a reviewer: aaron.ballman.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Although the default behaviour for C and C++ is to not diagnose ignored function
calls, we can make this the default by using `#pragma clang attribute
push([[nodiscard]],  apply_to = function)`. When we have a function that can
have its value discarded, we can use `[[clang::discardable]]` to indicate that
the ``[[nodiscard]]`` attribute should be ignored.

`[[clang::discardable]]` can be placed anywhere `[[nodiscard]]` is allowed,
but the presence of either is prioritised when it's applied to a callable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129835

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCXX/discardable.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129835.444886.patch
Type: text/x-patch
Size: 16232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220715/909dc15e/attachment.bin>


More information about the cfe-commits mailing list