Re: Solution to "statement is not reachable" depending on template variables?

2017-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 18 June 2017 at 11:11:59 UTC, Johan Engelen wrote: On Sunday, 18 June 2017 at 09:56:50 UTC, Steven Schveighoffer wrote: On Sunday, 18 June 2017 at 09:28:57 UTC, Johan Engelen wrote: Reviving this thread to see whether anything has changed on the topic. If Timon gets static for ea

Re: Solution to "statement is not reachable" depending on template variables?

2017-06-18 Thread Moritz Maxeiner via Digitalmars-d-learn
ggers that "statement is not reachable" if at least one of U1,U2,... = T is bool, will not occur if you instead use `static foreach (i, U; T)`.

Re: Solution to "statement is not reachable" depending on template variables?

2017-06-18 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 18 June 2017 at 09:56:50 UTC, Steven Schveighoffer wrote: On Sunday, 18 June 2017 at 09:28:57 UTC, Johan Engelen wrote: Reviving this thread to see whether anything has changed on the topic. If Timon gets static for each into the language, it can look a little better. Can you h

Re: Solution to "statement is not reachable" depending on template variables?

2017-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 18 June 2017 at 09:28:57 UTC, Johan Engelen wrote: Reviving this thread to see whether anything has changed on the topic. If Timon gets static for each into the language, it can look a little better. -Steve

Re: Solution to "statement is not reachable" depending on template variables?

2017-06-18 Thread Johan Engelen via Digitalmars-d-learn
Reviving this thread to see whether anything has changed on the topic. I now have this monster: ``` struct FMT { // has immutable members. FMT cannot be assigned to. } FMT monsterThatCompilerAccepts(T)(){ alias TP = Tuple!(__traits(getAttributes, T)); foreach(i, att; TP){ stat

Re: Solution to "statement is not reachable" depending on template variables?

2016-04-01 Thread ZombineDev via Digitalmars-d-learn
On Friday, 1 April 2016 at 01:21:32 UTC, Walter Bright wrote: On 3/16/2016 4:18 AM, Johan Engelen wrote: I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns

Re: Solution to "statement is not reachable" depending on template variables?

2016-04-01 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 April 2016 at 01:21:32 UTC, Walter Bright wrote: On 3/16/2016 4:18 AM, Johan Engelen wrote: I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-31 Thread Walter Bright via Digitalmars-d-learn
On 3/16/2016 4:18 AM, Johan Engelen wrote: I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ``` bool nobool(T...)() { foreach (i, U; T) {

Solution to "statement is not reachable" depending on template variables?

2016-03-20 Thread Johan Engelen via Digitalmars-d-learn
Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ``` bool nobool(T...)() { foreach (i, U; T) { static if (is(U == bool)) {

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/16/16 7:18 AM, Johan Engelen wrote: Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ``` bool nobool(T...)() { foreach (i, U; T) {

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
well. This will hopefully be fixed sooner or later: https://github.com/D-Programming-Language/dmd/pull/1913 https://github.com/D-Programming-Language/dmd/pull/5229 The only future-proof way to fix the "statement is not reachable" warning, is to guard the potentially unreachab

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Thursday, 17 March 2016 at 17:12:07 UTC, Steven Schveighoffer wrote: Yes. I agree. The way I look at it is that the code *is* reached in some cases, so it should compile (and just remove that section in that instance). IMO any time a template value is used for branching, it should turn tha

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread QAston via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 11:18:36 UTC, Johan Engelen wrote: Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ``` bool nobool(T...)

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 11:47:35 UTC, QAston wrote: import std.meta; template isBool(U)() = is(U == bool); static if (!allSatisfy!(isBool, T)) { return true; // no longer emits a warning } Something like this should work. Thanks, but: On Wednesday, 16 March 2016 at 11:18:36 UTC,

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread rikki cattermole via Digitalmars-d-learn
On 17/03/16 5:05 AM, Johan Engelen wrote: On Wednesday, 16 March 2016 at 11:22:02 UTC, rikki cattermole wrote: Change those static if's to just plain old ifs. But then this wouldn't compile, would it? ``` static if(__traits(compiles, __traits(getMember, a, "b"))) { return a.b; } ``` (real

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread QAston via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 17:08:20 UTC, Johan Engelen wrote: On Wednesday, 16 March 2016 at 11:47:35 UTC, QAston wrote: import std.meta; template isBool(U)() = is(U == bool); static if (!allSatisfy!(isBool, T)) { return true; // no longer emits a warning } Something like this should

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 17:34:13 UTC, Steven Schveighoffer wrote: On 3/16/16 7:18 AM, Johan Engelen wrote: Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread tsbockman via Digitalmars-d-learn
sooner or later: https://github.com/D-Programming-Language/dmd/pull/1913 https://github.com/D-Programming-Language/dmd/pull/5229 The only future-proof way to fix the "statement is not reachable" warning, is to guard the potentially unreachable code with a `static if` whose pred

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread rikki cattermole via Digitalmars-d-learn
On 16/03/16 11:18 PM, Johan Engelen wrote: Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ``` bool nobool(T...)() { foreach (i, U; T) {

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-18 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 11:22:02 UTC, rikki cattermole wrote: Change those static if's to just plain old ifs. But then this wouldn't compile, would it? ``` static if(__traits(compiles, __traits(getMember, a, "b"))) { return a.b; } ``` (real code, I am not making this up) Imagine tho

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-18 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 11:18:36 UTC, Johan Engelen wrote: Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns... "statement is not reachable

Re: Warning: statement is not reachable

2016-03-02 Thread Tamas via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 09:37:03 UTC, Johan Engelen wrote: On Wednesday, 2 March 2016 at 07:42:09 UTC, Tamas wrote: Thanks, fixing this single issue solved the compiler crash too. Did the compiler crash? Or just exit? (a crash would still be a bug) Crashed, just like in the case of Edw

Re: Warning: statement is not reachable

2016-03-02 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 07:42:09 UTC, Tamas wrote: Thanks, fixing this single issue solved the compiler crash too. Did the compiler crash? Or just exit? (a crash would still be a bug)

Re: Warning: statement is not reachable

2016-03-02 Thread Tamas via Digitalmars-d-learn
Thanks, fixing this single issue solved the compiler crash too. Thanks also for the tip using hasUDA! Works nicely!

Re: Warning: statement is not reachable

2016-03-02 Thread ag0aep6g via Digitalmars-d-learn
On 01.03.2016 22:30, Tamas wrote: struct Tag {} template isTagged(S) { enum bool isTagged = delegate() { foreach(attr; __traits(getAttributes, S)) { static if (is(attr == Tag)) { return true; } }

Re: Warning: statement is not reachable

2016-03-02 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 21:30:44 UTC, Tamas wrote: foreach(attr; __traits(getAttributes, S)) { static if (is(attr == Tag)) { return true; } } return false; }(); } void main() { static @Tag struct MyStru

Re: Warning: statement is not reachable

2016-03-02 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Tuesday, 1 March 2016 at 21:30:44 UTC, Tamas wrote: My d code doesn't compile using ldc2 1.0.0-alpha or anything above DMD v2.068.0 Using these compilers I get a lot of "Warning: statement is not reachable". Then the both compiler crashes. ldc2 -w reach.d dmd -w r

Warning: statement is not reachable

2016-03-02 Thread Tamas via Digitalmars-d-learn
My d code doesn't compile using ldc2 1.0.0-alpha or anything above DMD v2.068.0 Using these compilers I get a lot of "Warning: statement is not reachable". Then the both compiler crashes. I minimized the code to get the same warning, although the compilers do not crash thi

Re: statement is not reachable

2009-03-05 Thread Jarrett Billingsley
On Thu, Mar 5, 2009 at 10:45 AM, Qian Xu wrote: > Hi Jarrett, > > but I need an exception here. This is an unexpected case. I want no instance > to be create in this case. By the time the constructor runs, an instance has already been created. But if you throw an exception in the ctor, it's impo

Re: statement is not reachable

2009-03-05 Thread Ary Borenszweig
Qian Xu wrote: Jarrett Billingsley wrote: On Thu, Mar 5, 2009 at 3:17 AM, Qian Xu wrote: this(char[] s, int flag) { if (flag == 1) { this(1); return; } else if (flag == 2) { this("hello"); return; } throw new Exception("unhandled case"); this(0); // fake This line is unreachable. The 'thro

Re: statement is not reachable

2009-03-05 Thread Qian Xu
Jarrett Billingsley wrote: > On Thu, Mar 5, 2009 at 3:17 AM, Qian Xu > wrote: > >> this(char[] s, int flag) { >> if (flag == 1) >> { >> this(1); >> return; >> } >> else if (flag == 2) >> { >> this("hello"); >> return; >> } >> throw new Exception("unhandled case"); >> this(0); // fake > > This l

Re: statement is not reachable

2009-03-05 Thread Jarrett Billingsley
On Thu, Mar 5, 2009 at 3:17 AM, Qian Xu wrote: >  this(char[] s, int flag) { >    if (flag == 1) >    { >      this(1); >      return; >    } >    else if (flag == 2) >    { >      this("hello"); >      return; >    } >    throw new Exception("unhandled case"); >    this(0); // fake This line is

statement is not reachable

2009-03-05 Thread Qian Xu
-------------- The warning is: "statement is not reachable" If I use switch-case-statment, I can see even an error message: "constructor calls not allowed in loops or after labels" So, is my design incorrect, or is the compiler too strict? --Qian Xu