Should an 'extern(C++, "ns"):' override previous ones in the same scope?

Exil Exil at gmall.com
Sun Sep 8 18:12:53 UTC 2019


On Saturday, 7 September 2019 at 22:19:48 UTC, Jonathan M Davis 
wrote:
> On Saturday, September 7, 2019 3:40:58 PM MDT Exil via 
> Digitalmars-d-learn wrote:
>> On Saturday, 7 September 2019 at 17:22:07 UTC, Jonathan M Davis
>>
>> wrote:
>> > @safe:
>> > @system:
>> >
>> > then @system overrides @safe.
>>
>> Just to add onto this, you can't do:
>>
>>      @safe @system void foo(); // error
>>
>>
>> but you can do:
>>
>>      extern(C++, ns1) extern(C++, ns2) void foo(); // ok
>
> It makes no sense to apply multiple namespaces to the same 
> symbol. I expect that this behavior is due to a lack of testing 
> (the same with the out of order weirdness in the other post). 
> It's the sort of thing that you test when you're trying to make 
> sure that the feature does the right thing when people use it 
> incorrectly, not the sort of thing when you're trying to make 
> sure that the feature works as intended, so it's easy to forget.
>
> My guess is that this behavior leaked its way in due to the 
> fact that you
> need to be able to put multiple extern(C++) declarations on a 
> symbol when
> you use extern(C++, struct) or extern(C++, class) in addition 
> to the
> extern(C++) for the namespace.
>
> - Jonathan M Davis

You don't need to make guesses or assumptions. It most definitely 
was intentional.

https://github.com/dlang/dmd/commit/4b2578e208f2af9a02159fc2d8d87fb17b09005e#diff-62dcb5f0ffc3089b7565897d8beb3322R617


By the looks of it, this feature was also implemented before 
extern(C++, struct/class).



More information about the Digitalmars-d-learn mailing list