Bug 19278 – extern(C++, "name") doesn't accept expressions

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-10-01T01:36:42Z
Last change time
2018-11-05T18:03:28Z
Keywords
C++
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2018-10-01T01:36:42Z
Consider: ``` version (A) enum NS = "something"; else enum NS = "something_else"; extern(C++, NS): //... ``` In this example, the parser sees an identifier and assumes that to be the name for the namespace, rather than check if it's an expression that evaluates to a string. I think it should attempt to evaluate the expression as a string. It could be argued that may be ambiguous, but this isn't: ``` string GetNs() { version (A) { return "A"; } else { return "B"; } } extern(C++, GetNs()): ``` There's also this: ``` alias NS = AliasSeq!("A", "B"); extern(C++, NS): ``` That is, do want `extern(C++, "A", "B")` in this case, but again, it looks like an identifier to the parser. Various work-around constructions don't work: ``` version (A) extern(C++, "A"): else extern(C++, "B"): void f(); // <- f is not in any namespace, the externs are scoped inside the version cases ``` ``` mixin(`extern(C++, "NS"):`); void f(); // <- f is not namespaced; it seems the mixin statement has some sort of scope which the extern doesn't escape ``` One of the goals of the string namespace was that you could synthesise the name, so it really just needs to work with expressions.
Comment #1 by turkeyman — 2018-10-01T01:43:01Z
String expressions don't work (obviously) ``` extern (C++, "std" ~ (UseCxx11Namespace ? "::__1" : "")): ```
Comment #2 by turkeyman — 2018-10-06T22:52:28Z
Comment #3 by github-bugzilla — 2018-11-05T18:03:27Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/b596c4f8f26c102c996901894c867ddaba028820 Fix issue 19278 - extern(C++, "name") doesn't accept expressions https://github.com/dlang/dmd/commit/1965a43520a21115c31d42282e87ac4b6ff16cb1 Merge pull request #8787 from TurkeyMan/namespace_expr Fix issue 19278 - extern(C++, "name") doesn't accept expressions merged-on-behalf-of: Mathias LANG <[email protected]>