C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Attribute [[discard]] and attributes on expressions

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Fri, 13 Oct 2023 12:36:29 +0200
On 12/10/2023 19:26, Thiago Macieira via Std-Proposals wrote:
> On Thursday, 12 October 2023 06:57:09 PDT Sebastian Wittmeier via Std-
> Proposals wrote:
>> As Arthur wrote, you probably do not want to have [[maybe_unused]] active
>> for SOME_PLATFORM, too.
> Indeed.
>
> I don't want "maybe unused". I want a "definitely unused" attribute in my code,
> instead. "Maybe unused" is useful if you don't care either way, but if I want
> to be sure which way it was, it doesn't work.

IMHO this is now steering off-topic -- I don't see
[[discard]]/std::discard/... as a tool to signal that some automatic
variables are "definitely unused". It almost sounds as a contradiction,
as you would be using them (in the discarding "facility")?

void f(int i) {
    discard(i); // wait, `i` is used here...?
}


This kind of use case calls for another attribute/syntax, or some clever
macro usage, or similar. E.g.

#ifdef SOME_PLATFORM
#define SOME_PLATFORM_PARAM(x) (x)
#else
#define SOME_PLATFORM_PARAM(x)
#endif

void f(int SOME_PLATFORM_PARAM(i)) {
#ifdef SOME_PLATFORM
 // use i or get an unused warning
#else
 // don't have i at all, can't use it
#endif
}

--
Having said that, my complaints with a std::discard variadic function 
stay the same:
* it can't discard *all* sorts of expressions (void, bitfields, etc.)
* calling it with more than 1 argument is dangerous because you lose 
sequencing
* it's a library solution for a language problem
* it's not compatible with C
* it doesn't have a reason
Thanks,
-- 
Giuseppe D'Angelo

Received on 2023-10-13 10:36:33