Thread overview
[Issue 7417] One-definition rule for version specification - allow version expressions
Apr 26, 2016
Witold Baryluk
Jun 30, 2019
Basile-z
Sep 16, 2019
anonymous4
Jun 10, 2021
anonymous4
Jun 10, 2021
anonymous4
Jun 10, 2021
anonymous4
Jun 10, 2021
anonymous4
Jun 10, 2021
anonymous4
Dec 17, 2022
Iain Buclaw
April 26, 2016
https://issues.dlang.org/show_bug.cgi?id=7417

Witold Baryluk <baryluk@smp.if.uj.edu.pl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |baryluk@smp.if.uj.edu.pl

--- Comment #6 from Witold Baryluk <baryluk@smp.if.uj.edu.pl> ---
Hi. Any update on this.

I was just trying to compiled phobos using gdc on arm64, and of course first thing that failed was a static assert in libdruntime/core/sys/posix/sys/socket.d that do have about 10 different semi duplicated version branches.

I would really want to say:

version (ARM || AArch64 || PPC || PPC64 || MIPS32 || MIPS64 || X86 || X86_64) {
  ...
} else version (SomethingSpecial) {
  ...
} else {
  static assert(0);
}


That would be good enough in most cases.

Support for more elaborate conditions would be nice too.

instead of

version (A) {
} else {
  somethign special.
}


version (!A) {
  something special.
}


or

version (A) {
version (B) {
  something.
}
}
version (A && B) {
  something.
}

It is probably possible to implement what I want using mixing and putting common code in the template, and then expand

version (ARM || AArch64 || PPC || PPC64 || MIPS32 || MIPS64 || X86 || X86_64) {


into separate branches with mixed-in template. Still I fell, explicit booleans support on versions would be nicer.

BTW. The mentioned file also shows almost the same enums in the OSX and FreeBSD branches, so maybe in this case it is worth doing this via mixin, as the OSX and FreeBSD branches cannot be really folded easily into one version (OSX || FreeBSD) branch. Same with Android (with do have same enum values as Linux).

--
June 30, 2019
https://issues.dlang.org/show_bug.cgi?id=7417

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrew.pennebaker@gmail.com

--- Comment #7 from Basile-z <b2.temp@gmx.com> ---
*** Issue 19495 has been marked as a duplicate of this issue. ***

--
September 16, 2019
https://issues.dlang.org/show_bug.cgi?id=7417

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |black80@bk.ru

--- Comment #8 from anonymous4 <dfj1esp02@sneakemail.com> ---
*** Issue 20210 has been marked as a duplicate of this issue. ***

--
June 10, 2021
https://issues.dlang.org/show_bug.cgi?id=7417

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=12887

--
June 10, 2021
https://issues.dlang.org/show_bug.cgi?id=7417

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alexanderheistermann@gmail.
                   |                            |com

--- Comment #9 from anonymous4 <dfj1esp02@sneakemail.com> ---
*** Issue 21999 has been marked as a duplicate of this issue. ***

--
June 10, 2021
https://issues.dlang.org/show_bug.cgi?id=7417

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec

--- Comment #10 from anonymous4 <dfj1esp02@sneakemail.com> ---
Workaround:
---
template Defined(string s)
{
    mixin(`version(`~s~`)enum Defined=true;else enum Defined=false;`);
}

struct SVersion
{
    alias opDispatch(string s)=Defined!s;
}
enum Version=SVersion();

int main()
{
    static if(Version.OSX)writeln("running OSX");
    else writeln("no");
    return 0;
}
---

--
June 10, 2021
https://issues.dlang.org/show_bug.cgi?id=7417

--- Comment #11 from anonymous4 <dfj1esp02@sneakemail.com> ---
Minimal implementation with static opDispatch:
---
struct Version
{
    template opDispatch(string s)
    {
        mixin(`version(`~s~`)enum opDispatch=true;else enum
opDispatch=false;`);
    }
}

static if(Version.OSX || Version.linux){}
else{}
---

--
June 10, 2021
https://issues.dlang.org/show_bug.cgi?id=7417

--- Comment #12 from anonymous4 <dfj1esp02@sneakemail.com> ---
I'm in favor of addition of version(true) and version(false), because "all" and
"none" aren't keywords and I'm never sure if I typed them correctly, but
failure to type them correctly is often silent. Also version(true) and
version(false) feel more intuitively understandable than version(all) and
version(none).

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=7417

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P4

--