www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Diagnostics for redundant qualifiers

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
What about making

```d
 safe struct S  {
    void f()  safe {}
}
```

warn or deprecate as

```
Warning: redundant function attribute ` safe`
```

?
Jul 28 2021
next sibling parent Paul Backus <snarwin gmail.com> writes:
On Wednesday, 28 July 2021 at 18:54:12 UTC, Per Nordlöw wrote:
 What about making

 ```d
  safe struct S  {
    void f()  safe {}
 }
 ```

 warn or deprecate as

 ```
 Warning: redundant function attribute ` safe`
 ```

 ?
What's the harm in allowing redundant attributes? Generally, warnings are helpful when they point out code that is likely to do something different from what the programmer intended (e.g., `if (a = b)`). If the programmer wrote ` safe` in two places, I'd say there's very little chance they did it by mistake.
Jul 28 2021
prev sibling next sibling parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Wednesday, 28 July 2021 at 18:54:12 UTC, Per Nordlöw wrote:
 What about making

 ```d
  safe struct S  {
    void f()  safe {}
 }
 ```

 warn or deprecate as

 ```
 Warning: redundant function attribute ` safe`
 ```

 ?
No, think about if `f` is generated from a string or template mixin.
Jul 28 2021
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 7/28/2021 11:54 AM, Per Nordlöw wrote:
 What about making
 
 ```d
  safe struct S  {
     void f()  safe {}
 }
 ```
 
 warn or deprecate as
 
 ```
 Warning: redundant function attribute ` safe`
 ```
 
 ?
The compiler will complain about: safe safe void test(); but not: safe { safe void test(); } safe: safe void bar(); This is quite deliberate. It's the same for all the attributes. Nicholas has the right justification.
Jul 29 2021
parent Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Thursday, 29 July 2021 at 17:22:28 UTC, Walter Bright wrote:
 This is quite deliberate. It's the same for all the attributes.

 Nicholas has the right justification.
Seems reasonable. Thanks.
Jul 30 2021