Should an 'extern(C++, "ns"):' override previous ones in the same scope?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Sat Sep 7 17:22:07 UTC 2019
On Saturday, September 7, 2019 9:15:44 AM MDT Max Samukha via Digitalmars-d-
learn wrote:
> extern(C++, "ns1"):
> extern(C++, "ns2"): // Not in nested scope. Should it supersede?
> void foo();
>
> pragma(msg, foo.mangleof); // _ZN3ns13ns23fooEv instead of
> expected _ZN3ns23fooEv
>
> Is that by design?
If you have
@safe:
@system:
then @system overrides @safe. And you can't have a C++ symbol that lives in
multiple namespaces. So, I would consider it a bug if your example doesn't
put foo in the namespace ns2, overriding ns1. IMHO, overriding is the only
behavior that makes sense, and anything else would be inconsistent with how
other, incompatible attributes are applied. Certainly, treating
extern(C++, "ns1"):
extern(C++, "ns2"):
as equivalent to
extern(C++, "ns1::ns2"):
makes no sense whatsoever IMHO. IIRC, this version of extern(C++) didn't go
through the DIP process and was simply added via a PR. So, it wouldn't
surprise me if the person who implemented it didn't even think about the
extern(C++, "ns1"):
extern(C++, "ns2"):
case and didn't test for it properly.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list