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

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Sep 7 22:19:48 UTC 2019


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





More information about the Digitalmars-d-learn mailing list