[Issue 12892] extern(C): label confined to version scope

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 11 13:40:25 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12892

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
This has come up in the forums:

http://forum.dlang.org/thread/mailman.1308.1401315810.2907.digitalmars-d-announce@puremagic.com?page=3#post-lmdoga:241ab3:241:40digitalmars.com

Which I'll quote:

On 5/30/2014 5:37 AM, Steven Schveighoffer wrote:
> On Thu, 29 May 2014 21:15:21 -0400, deadalnix <deadalnix at gmail.com> wrote:
>
>> On Thursday, 29 May 2014 at 19:06:15 UTC, Steven Schveighoffer
>> wrote:
>>>> Static if is certainly NOT an attribute, it doesn't make any sense.
>>>
>>> Well... it sorta does. static if does not introduce a new scope, even with
>>> {}, and this only happens with attributes.
>>>
>>> -Steve
>>
>> in which case
>>
>> static if(cond) {
>> immutable:
>> }
>>
>> int x;
>>
>> should not create x as immutable if cond is true. The current
>> behavior is not consistent with attribute either.
>
> Ugh, that is really bad. It shouldn't do that. Is that intentional?

Yes. Semantic scope and lexical scope are different things. The ':' thing 
applies to the remaining statements in the lexical scope. 'static if' does not 
create a new semantic scope, even though the { } suggests it does.

There have been several suggestions to make 'static if' apply independently of 
the rest of the grammar, i.e. allow things like:

    int static if (cond) * else [ ] foo; // conditionally make foo a pointer or 
an array

I think we can agree that looks awful, but it is the same thing as suggesting 
that the 'immutable:' above extend outside of its lexical scope.


You might ask "why is semantic scope different from lexical scope" and the 
reason is simply that 'static if' would not be very useful if that were the
case.

--


More information about the Digitalmars-d-bugs mailing list