D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17911 - Add { } block attributes for local variables
Summary: Add { } block attributes for local variables
Status: RESOLVED DUPLICATE of issue 11064
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-17 14:49 UTC by Timoses
Modified: 2020-06-13 18:36 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Timoses 2017-10-17 14:49:35 UTC
The example for user defined attributes (UDA) on https://dlang.org/spec/attribute.html#uda does not work:


@(1)
{
    @(2) int a;         // has UDA's (1, 2)
    @("string") int b;  // has UDA's (1, "string")
}


causes:
src\app.d(59,5): Error: basic type expected, not {
src\app.d(59,5): Error: no identifier for declarator _error_


The same is caused by


@(1) {}


DMD32 D Compiler v2.074.0
Comment 1 Walter Bright 2018-05-17 04:31:32 UTC
Why is this marked as a regression? Which compiler version did it work on?
Comment 2 Mike Franklin 2018-05-17 04:50:10 UTC
I cannot reproduce this in either Linux (2.080) or Windows (2.079). 

You can also see that it works fine at https://run.dlang.io/is/v6SW8Q 

Please reopen and supply a complete module with precise compiler flags to reproduce the symptoms if the problem persists.
Comment 3 Andrea Fontana 2018-05-17 07:22:41 UTC
Probably this is the problem he found:

https://run.dlang.io/is/zim8Z0
Comment 4 Timoses 2018-05-17 13:15:04 UTC
I apologize in case I have reported the bug incorrectly.


Indeed, I mean Andrea Fontana's version.

The following clarifies a bit more perhaps:

------------------------------------------------------
struct F 
{
    @(1) // works!
    {
        @(2) int a;         // has UDA's (1, 2)
        @("string") int b;  // has UDA's (1, "string")
    }
}

void func() 
{
    @(1) // compilation error
    {
        @(2) int a;         // has UDA's (1, 2)
        @("string") int b;  // has UDA's (1, "string")
    }
}

void main() 
{ 
    
    struct G 
    {
        @(1) // works!
        {
            @(2) int a;         // has UDA's (1, 2)
            @("string") int b;  // has UDA's (1, "string")
        }
    }
}
-----------------------------------------------------

I'm not sure whether attribution of local variables makes any sense anyhow. Does it? If that were the case the error message coule be more descriptive.
Comment 5 Walter Bright 2018-12-16 11:14:26 UTC
The { } attribute syntax is not supported for local variables:

void bar()
{
    const { int a = 3; }
}

It's never been supported, so it's not a regression. Marked as enhancement request.
Comment 6 basile-z 2020-06-13 18:36:55 UTC

*** This issue has been marked as a duplicate of issue 11064 ***