DIP 1038: @nodiscard - Unofficial "post-final" review

Paul Backus snarwin at gmail.com
Fri Feb 26 20:38:24 UTC 2021


On Friday, 26 February 2021 at 20:00:52 UTC, Jacob Carlborg wrote:
> On 2021-02-23 00:32, Paul Backus wrote:
>
>> @nodiscard is a user-defined attribute, and the compiler 
>> currently allows multiple declarations of a function that 
>> differ only by UDAs. [1] Again, I agree that this should 
>> probably be an error, but since it is an issue that affects 
>> UDAs in general, it should be addressed in a Bugzilla issue, 
>> not DIP 1038.
[...]
> If you say that you cannot add a specific semantic behavior to 
> a compiler recognized UDA because it's a UDA it all falls 
> apart. If you don't add any special semantic behavior at 
> **all**, it would just be a regular UDA.

You've misread me. I am not saying that I *cannot* add this 
behavior specifically for @nodiscard, I am saying that I *should 
not*, because the current behavior is a bug that affects other 
attributes as well.

Maybe you meant to reply to the part of the post about 
inheritance? Certainly it would be possible to have overrides of 
virtual methods inherit @nodiscard, or at least to forbid them 
from dropping it. The question is whether that's actually a good 
idea.

Personally, I think the increased spec and implementation 
complexity would not be worth the benefit you'd get--especially 
since it would only apply to the weak syntax-level check, which 
is trivial to defeat even if you plug this particular hole.

It's worth noting that [[nodiscard]] is not inherited in C++. [1]

[1] 
https://stackoverflow.com/questions/49576298/are-function-attributes-inherited


More information about the Digitalmars-d mailing list