[PATCH] D129835: [clang] adds a discardable attribute
Christopher Di Bella via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 21 10:07:36 PDT 2023
cjdb added a comment.
>> With [[discardable]] one just needs to push/pop at the extremes of a file (and if a future version of module maps supports global pragmas for a module, there too, but that's a discussion that requires a design doc).
>
> I understood that, I just don't think that's a good thing. This is basically an attribute that says "I know we said we wanted everything here to be nodiscard, but JUST KIDDING not this one!" which is not a very clean approach to writing headers.
@aaron.ballman Ugh, I've finally come up with a good use-case for `[[discardable]]`.
class [[nodiscard]] iterator {
public:
// usual iterator stuff
[[clang::discardable]] iterator operator++(int);
[[clang::discardable]] iterator operator--(int);
};
I hate it, but the alternative is to decorate everything else with `[[nodiscard]]` just to facilitate these two operators. It's a compelling use-case, but I'm not sure if it's compelling enough on its own. WDYT?
(I personally think that those two should be nodiscard, but `i++` is pervasive enough that it might never be practical to correct.)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129835/new/
https://reviews.llvm.org/D129835
More information about the cfe-commits
mailing list