Should an 'extern(C++, "ns"):' override previous ones in the same scope?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Sun Sep 8 09:35:03 UTC 2019
On Sunday, September 8, 2019 3:03:31 AM MDT Max Samukha via Digitalmars-d-
> On Saturday, 7 September 2019 at 22:19:48 UTC, Jonathan M Davis
> > 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
> I wonder how that undocumented and not well thought-through (or
> having some unobvious justifications) feature made it into a
> stable release.
> Anyway, thank you for your help. I will probably file a bug
> report when I have time.
The C++ support has been improved kind of piecemeal over time, and
initially, none of it was documented. So, it wasn't exactly fully planned
out when it was added. IIRC, it was added originally so that the dmd
frontend could be moved to D. The DIP process was very different at that
point, and it was much more common then for Walter or one of the other core
developers to just propose a feature in a PR and get it merged. I expect
that the oddities in the implementation stem from stuff that whoever
implemented it didn't think to try. The whole process is much more rigorous
now than it used to be.
- Jonathan M Davis
More information about the Digitalmars-d-learn