Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 26, 2017 Empty UDA for classes not allowed? | ||||
---|---|---|---|---|
| ||||
Why is it not allowed to have empty UDAs for classes? Let's say we have an UDA like this: struct Exclude { } Then we want to put it on a class like: @Exclude class Foo { ... } This will fail with the following error: Error: type Exclude has no value But on everything else we can place an empty UDA like that ex. on a function: This is okay: @Exclude void foo() { ... } Can someone explain to me why it's not possible with classes? |
October 26, 2017 Re: Empty UDA for classes not allowed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bauss | On Thursday, October 26, 2017 15:09:48 bauss via Digitalmars-d-learn wrote:
> Why is it not allowed to have empty UDAs for classes?
>
> Let's say we have an UDA like this:
> struct Exclude { }
>
> Then we want to put it on a class like:
>
> @Exclude class Foo
> {
> ...
> }
>
> This will fail with the following error:
> Error: type Exclude has no value
>
> But on everything else we can place an empty UDA like that ex. on a function:
>
> This is okay:
>
> @Exclude void foo()
> {
> ...
> }
>
> Can someone explain to me why it's not possible with classes?
It worked just fine when I just tried it on my machine - both with dmd master and with 2.076.1. Are you using an older version of the compiler than 2.076.1? It's possible that there was a bug that was fixed.
- Jonathan M Davis
|
October 26, 2017 Re: Empty UDA for classes not allowed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Thursday, 26 October 2017 at 21:24:43 UTC, Jonathan M Davis wrote:
> On Thursday, October 26, 2017 15:09:48 bauss via Digitalmars-d-learn wrote:
>> [...]
>
> It worked just fine when I just tried it on my machine - both with dmd master and with 2.076.1. Are you using an older version of the compiler than 2.076.1? It's possible that there was a bug that was fixed.
>
> - Jonathan M Davis
Yeah I can't reproduce it right now, so I'm not even sure.
|
October 27, 2017 Re: Empty UDA for classes not allowed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bauss | On Thursday, 26 October 2017 at 15:09:48 UTC, bauss wrote: > Why is it not allowed to have empty UDAs for classes? > > Let's say we have an UDA like this: > struct Exclude { } > > Then we want to put it on a class like: > > @Exclude class Foo > { > ... > } > > This will fail with the following error: > Error: type Exclude has no value > > But on everything else we can place an empty UDA like that ex. on a function: > > This is okay: > > @Exclude void foo() > { > ... > } > > Can someone explain to me why it's not possible with classes? FWIW all parameterless UDA in LDC use a struct literal e.g. https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/attributes.d#L237 |
Copyright © 1999-2021 by the D Language Foundation