Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Mystics always hope that science will some day overtake them. -- Booth Tarkington


devel / comp.lang.c++ / Re: Unglaublich, dass das funktioniert:

SubjectAuthor
* Unglaublich, dass das funktioniert:Bonita Montero
+- Re: Unglaublich, dass das funktioniert:Bo Persson
+- Re: Unglaublich, dass das funktioniert:Pavel
+* Re: Unglaublich, dass das funktioniert:James Kuyper
|`* Re: Unglaublich, dass das funktioniert:Bonita Montero
| +* Re: Unglaublich, dass das funktioniert:Kaz Kylheku
| |+- Re: Unglaublich, dass das funktioniert:immibis
| |`* Re: Unglaublich, dass das funktioniert:Bonita Montero
| | +- Re: Unglaublich, dass das funktioniert:Kaz Kylheku
| | `- Re: Unglaublich, dass das funktioniert:James Kuyper
| `* Re: Unglaublich, dass das funktioniert:James Kuyper
|  +* Re: Unglaublich, dass das funktioniert:Bonita Montero
|  |`* Re: Unglaublich, dass das funktioniert:David Brown
|  | `* Re: Unglaublich, dass das funktioniert:Bonita Montero
|  |  `- Re: Unglaublich, dass das funktioniert:David Brown
|  `* Re: Unglaublich, dass das funktioniert:James Kuyper
|   +* Re: Unglaublich, dass das funktioniert:Bonita Montero
|   |`* Re: Unglaublich, dass das funktioniert:David Brown
|   | +- Re: Unglaublich, dass das funktioniert:Bonita Montero
|   | `* Re: Unglaublich, dass das funktioniert:Kaz Kylheku
|   |  `- Re: Unglaublich, dass das funktioniert:Bonita Montero
|   `* Re: Unglaublich, dass das funktioniert:James Kuyper
|    `- Re: Unglaublich, dass das funktioniert:Bonita Montero
`* Re: Unglaublich, dass das funktioniert:Andrey Tarasevich
 +* Re: Unglaublich, dass das funktioniert:Ralf Goertz
 |`* Re: Unglaublich, dass das funktioniert:Andrey Tarasevich
 | `* Re: Unglaublich, dass das funktioniert:Ralf Goertz
 |  +* Re: Unglaublich, dass das funktioniert:Andreas Kempe
 |  |`* Re: Unglaublich, dass das funktioniert:Andreas Kempe
 |  | `* Re: Unglaublich, dass das funktioniert:Andrey Tarasevich
 |  |  `- Re: Unglaublich, dass das funktioniert:Andreas Kempe
 |  `* Re: Unglaublich, dass das funktioniert:Andrey Tarasevich
 |   `* Re: Unglaublich, dass das funktioniert:Ben Bacarisse
 |    `* Re: Unglaublich, dass das funktioniert:Pavel
 |     +- Re: Unglaublich, dass das funktioniert:Ben Bacarisse
 |     `- Re: Unglaublich, dass das funktioniert:Tim Rentsch
 `- Re: Unglaublich, dass das funktioniert:Kaz Kylheku

Pages:12
Re: Unglaublich, dass das funktioniert:

<um2rck$19qhc$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2939&group=comp.lang.c%2B%2B#2939

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Thu, 21 Dec 2023 18:13:39 -0800
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <um2rck$19qhc$1@dont-email.me>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Dec 2023 02:13:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="14738ad61c3d8a0ffebd03bc8bfe67d1";
logging-data="1370668"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19o47rYKKYxwtSMBsLoqfEg"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:nvdXwIwwNvCe7wPESmPTFyGvYt0=
Content-Language: en-US
In-Reply-To: <um0pph$100f7$1@dont-email.me>
 by: Andrey Tarasevich - Fri, 22 Dec 2023 02:13 UTC

On 12/20/23 11:34 PM, Ralf Goertz wrote:
> On Wed, 20 Dec 2023 22:56:24 -0800
> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>
>> Meh... An old example of break-less switch-case branching
>>
>> #include <iostream>
>>
>> int main(int argc, char **)
>> {
>> switch (argc)
>> if (0) case 1: std::cout << 1 << std::endl;
>> else if (0) case 2: std::cout << 2 << std::endl;
>> else if (0) case 3: std::cout << 3 << std::endl;
>> else if (0) default: std::cout << "whatever" << std::endl;
>> }
>>
>> As illustrated above, even if the body of switch is not enclosed into
>> `{ ... }`, one can still stuff a lot into a single protracted
>> statement, including multiple `case` labels.
>
> Interestingly enough, I get a warning with gcc:
>
> warning: statement will never be executed [-Wswitch-unreachable]
> if (0) case 1: std::cout << 1 << std::endl;
>
> although of course I still see the output of “1” when the program is
> called without arguments.

The compiler complains specifically about the `if (0)` part, not about
the part that outputs 1. The `if (0)` part precedes the first `case`
label and for that reason it is indeed unreachable.

--
Best regards,
Andrey

Re: Unglaublich, dass das funktioniert:

<um3nea$1h1gc$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2942&group=comp.lang.c%2B%2B#2942

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: me...@myprovider.invalid (Ralf Goertz)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Fri, 22 Dec 2023 11:12:26 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <um3nea$1h1gc$1@dont-email.me>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me>
<um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Date: Fri, 22 Dec 2023 10:12:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b00567cfead1ac61dcdf3ed367acc34f";
logging-data="1607180"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9V54DpCWfRFyEtChiM9gN"
Cancel-Lock: sha1:bJlwt/+4tstYObkpY/WBCyKzdyU=
X-Newsreader: Claws Mail 4.2.0 (GTK 3.24.39; x86_64-suse-linux-gnu)
 by: Ralf Goertz - Fri, 22 Dec 2023 10:12 UTC

Am Thu, 21 Dec 2023 18:13:39 -0800
schrieb Andrey Tarasevich <andreytarasevich@hotmail.com>:

> On 12/20/23 11:34 PM, Ralf Goertz wrote:
>> On Wed, 20 Dec 2023 22:56:24 -0800
>> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>>
>>> Meh... An old example of break-less switch-case branching
>>>
>>> #include <iostream>
>>>
>>> int main(int argc, char **)
>>> {
>>> switch (argc)
>>> if (0) case 1: std::cout << 1 << std::endl;
>>> else if (0) case 2: std::cout << 2 << std::endl;
>>> else if (0) case 3: std::cout << 3 << std::endl;
>>> else if (0) default: std::cout << "whatever" << std::endl;
>>> }
>>>
>>> As illustrated above, even if the body of switch is not enclosed
>>> into `{ ... }`, one can still stuff a lot into a single protracted
>>> statement, including multiple `case` labels.
>>
>> Interestingly enough, I get a warning with gcc:
>>
>> warning: statement will never be executed [-Wswitch-unreachable]
>> if (0) case 1: std::cout << 1 << std::endl;
>>
>> although of course I still see the output of “1” when the program is
>> called without arguments.
>
> The compiler complains specifically about the `if (0)` part, not
> about the part that outputs 1.

Hm, I obviously get that the `if (0)` condition can't ever be fulfilled,
but according to <https://en.cppreference.com/w/cpp/language/statements>
selection statements (1,2) the statement after the condition statement
is part of the if statement. So part of the if statement may still be
executed. Furthermore, it says -Wswitch-unreachable. That is misleading
imho since it is exactly the switch case label that is reachable.

> The `if (0)` part precedes the first `case` label and for that reason
> it is indeed unreachable.

I understand that but gcc knows that labeled part might be executed
despite the unfulfilled condition. So it should refrain from warning.
And why are the other `if (0) case x:` statements not complained about?
They live in an else branch of a guaranteed false condition, so they are
not unreachable and that branch will be executed. So gcc should
warn about them, too. No?

Re: Unglaublich, dass das funktioniert:

<um3trt$1hp7$3@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2943&group=comp.lang.c%2B%2B#2943

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Fri, 22 Dec 2023 12:02:05 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <um3trt$1hp7$3@nyheter.lysator.liu.se>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Dec 2023 12:02:05 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="50983"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Fri, 22 Dec 2023 12:02 UTC

Den 2023-12-22 skrev Ralf Goertz <me@myprovider.invalid>:
> Am Thu, 21 Dec 2023 18:13:39 -0800
> schrieb Andrey Tarasevich <andreytarasevich@hotmail.com>:
>
>> On 12/20/23 11:34 PM, Ralf Goertz wrote:
>>> On Wed, 20 Dec 2023 22:56:24 -0800
>>> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>>>
>>>> Meh... An old example of break-less switch-case branching
>>>>
>>>> #include <iostream>
>>>>
>>>> int main(int argc, char **)
>>>> {
>>>> switch (argc)
>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>> else if (0) case 2: std::cout << 2 << std::endl;
>>>> else if (0) case 3: std::cout << 3 << std::endl;
>>>> else if (0) default: std::cout << "whatever" << std::endl;
>>>> }
>>>>
>>>> As illustrated above, even if the body of switch is not enclosed
>>>> into `{ ... }`, one can still stuff a lot into a single protracted
>>>> statement, including multiple `case` labels.
>>>
>>> Interestingly enough, I get a warning with gcc:
>>>
>>> warning: statement will never be executed [-Wswitch-unreachable]
>>> if (0) case 1: std::cout << 1 << std::endl;
>>>
>>> although of course I still see the output of “1” when the program is
>>> called without arguments.
>>
>> The compiler complains specifically about the `if (0)` part, not
>> about the part that outputs 1.
>
> Hm, I obviously get that the `if (0)` condition can't ever be fulfilled,
> but according to <https://en.cppreference.com/w/cpp/language/statements>
> selection statements (1,2) the statement after the condition statement
> is part of the if statement. So part of the if statement may still be
> executed. Furthermore, it says -Wswitch-unreachable. That is misleading
> imho since it is exactly the switch case label that is reachable.
>
>> The `if (0)` part precedes the first `case` label and for that reason
>> it is indeed unreachable.
>
> I understand that but gcc knows that labeled part might be executed
> despite the unfulfilled condition. So it should refrain from warning.
> And why are the other `if (0) case x:` statements not complained about?
> They live in an else branch of a guaranteed false condition, so they are
> not unreachable and that branch will be executed. So gcc should
> warn about them, too. No?
>

I don't know if we have any specific language for having the compiler
warn about the test in the if-statement being unreachable while the
true branch is. Considering this is such a weird edge case, I don't
know if we need it.

As for the statements not warned about, they aren't warned about
because the if (0) tests are reachable via fallthrough from the
previous case labels. The test is reachable via fallthrough while
the branch is reachable via switching to the case labels so all that
code is reachable.

Re: Unglaublich, dass das funktioniert:

<um3v6n$1hp7$4@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2944&group=comp.lang.c%2B%2B#2944

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Fri, 22 Dec 2023 12:24:55 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <um3v6n$1hp7$4@nyheter.lysator.liu.se>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me>
<um3trt$1hp7$3@nyheter.lysator.liu.se>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Dec 2023 12:24:55 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="50983"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Fri, 22 Dec 2023 12:24 UTC

Den 2023-12-22 skrev Andreas Kempe <kempe@lysator.liu.se>:
> Den 2023-12-22 skrev Ralf Goertz <me@myprovider.invalid>:
>> Am Thu, 21 Dec 2023 18:13:39 -0800
>> schrieb Andrey Tarasevich <andreytarasevich@hotmail.com>:
>>
>>> On 12/20/23 11:34 PM, Ralf Goertz wrote:
>>>> On Wed, 20 Dec 2023 22:56:24 -0800
>>>> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>>>>
>>>>> Meh... An old example of break-less switch-case branching
>>>>>
>>>>> #include <iostream>
>>>>>
>>>>> int main(int argc, char **)
>>>>> {
>>>>> switch (argc)
>>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>> else if (0) case 2: std::cout << 2 << std::endl;
>>>>> else if (0) case 3: std::cout << 3 << std::endl;
>>>>> else if (0) default: std::cout << "whatever" << std::endl;
>>>>> }
>>>>>
>>>>> As illustrated above, even if the body of switch is not enclosed
>>>>> into `{ ... }`, one can still stuff a lot into a single protracted
>>>>> statement, including multiple `case` labels.
>>>>
>>>> Interestingly enough, I get a warning with gcc:
>>>>
>>>> warning: statement will never be executed [-Wswitch-unreachable]
>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>
>>>> although of course I still see the output of “1” when the program is
>>>> called without arguments.
>>>
>>> The compiler complains specifically about the `if (0)` part, not
>>> about the part that outputs 1.
>>
>> Hm, I obviously get that the `if (0)` condition can't ever be fulfilled,
>> but according to <https://en.cppreference.com/w/cpp/language/statements>
>> selection statements (1,2) the statement after the condition statement
>> is part of the if statement. So part of the if statement may still be
>> executed. Furthermore, it says -Wswitch-unreachable. That is misleading
>> imho since it is exactly the switch case label that is reachable.
>>
>>> The `if (0)` part precedes the first `case` label and for that reason
>>> it is indeed unreachable.
>>
>> I understand that but gcc knows that labeled part might be executed
>> despite the unfulfilled condition. So it should refrain from warning.
>> And why are the other `if (0) case x:` statements not complained about?
>> They live in an else branch of a guaranteed false condition, so they are
>> not unreachable and that branch will be executed. So gcc should
>> warn about them, too. No?
>>
>
> I don't know if we have any specific language for having the compiler
> warn about the test in the if-statement being unreachable while the
> true branch is. Considering this is such a weird edge case, I don't
> know if we need it.
>
> As for the statements not warned about, they aren't warned about
> because the if (0) tests are reachable via fallthrough from the
> previous case labels. The test is reachable via fallthrough while
> the branch is reachable via switching to the case labels so all that
> code is reachable.

After thinking some more, I relise I don't know if my fallthrough idea
holds water considering the else if construct. The first statement is
false so the second statement should be tested, but we're jumping into
the true branch, which if taken should prevent the other test from
happening. Does anyone have pointers to relevant parts of the standard
that handle this weirdness?

Re: Unglaublich, dass das funktioniert:

<um5dc9$1pfu5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2946&group=comp.lang.c%2B%2B#2946

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Fri, 22 Dec 2023 17:32:55 -0800
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <um5dc9$1pfu5$1@dont-email.me>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Dec 2023 01:32:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed36f1cf2d5ec40d0a89cc03559c1df8";
logging-data="1884101"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ExcbTJPVCZ77PlOOVMvKH"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kAiKG8awQyM2u+wTg1iqRyTVLbs=
Content-Language: en-US
In-Reply-To: <um3nea$1h1gc$1@dont-email.me>
 by: Andrey Tarasevich - Sat, 23 Dec 2023 01:32 UTC

On 12/22/23 2:12 AM, Ralf Goertz wrote:
> Am Thu, 21 Dec 2023 18:13:39 -0800
> schrieb Andrey Tarasevich <andreytarasevich@hotmail.com>:
>
>> On 12/20/23 11:34 PM, Ralf Goertz wrote:
>>> On Wed, 20 Dec 2023 22:56:24 -0800
>>> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>>>
>>>> Meh... An old example of break-less switch-case branching
>>>>
>>>> #include <iostream>
>>>>
>>>> int main(int argc, char **)
>>>> {
>>>> switch (argc)
>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>> else if (0) case 2: std::cout << 2 << std::endl;
>>>> else if (0) case 3: std::cout << 3 << std::endl;
>>>> else if (0) default: std::cout << "whatever" << std::endl;
>>>> }
>>>>
>>>> As illustrated above, even if the body of switch is not enclosed
>>>> into `{ ... }`, one can still stuff a lot into a single protracted
>>>> statement, including multiple `case` labels.
>>>
>>> Interestingly enough, I get a warning with gcc:
>>>
>>> warning: statement will never be executed [-Wswitch-unreachable]
>>> if (0) case 1: std::cout << 1 << std::endl;
>>>
>>> although of course I still see the output of “1” when the program is
>>> called without arguments.
>>
>> The compiler complains specifically about the `if (0)` part, not
>> about the part that outputs 1.
>
> Hm, I obviously get that the `if (0)` condition can't ever be fulfilled,
> but according to <https://en.cppreference.com/w/cpp/language/statements>
> selection statements (1,2) the statement after the condition statement
> is part of the if statement. So part of the if statement may still be
> executed.

This has absolutely nothing to do with the fulfillability of if's
condition. You can replace `if (0)` with `if (1)` and you will still get
the same warning. The properties of that `if` are completely beside the
point here.

What matters is that the compiler sees some tangible code (i.e. not a
no-op declaration, but something that can potentially generate
executable instructions), which precedes the very first `case` label.
That code is unreachable for obvious reasons, since `switch` will always
jump over it. Hence the warning.

--
Best regards,
Andrey

Re: Unglaublich, dass das funktioniert:

<um5dih$1pfu5$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2947&group=comp.lang.c%2B%2B#2947

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Fri, 22 Dec 2023 17:36:15 -0800
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <um5dih$1pfu5$2@dont-email.me>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me>
<um3trt$1hp7$3@nyheter.lysator.liu.se> <um3v6n$1hp7$4@nyheter.lysator.liu.se>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Dec 2023 01:36:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed36f1cf2d5ec40d0a89cc03559c1df8";
logging-data="1884101"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7kdGoAmFY0alZVkvRb1ZC"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:oPsIF5opPcppwBCky3MlGh8iph0=
In-Reply-To: <um3v6n$1hp7$4@nyheter.lysator.liu.se>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 23 Dec 2023 01:36 UTC

On 12/22/23 4:24 AM, Andreas Kempe wrote:
>
> After thinking some more, I relise I don't know if my fallthrough idea
> holds water considering the else if construct. The first statement is
> false so the second statement should be tested, but we're jumping into
> the true branch, which if taken should prevent the other test from
> happening. Does anyone have pointers to relevant parts of the standard
> that handle this weirdness?

Yes, the standard states it explicitly right at the beginning of "8.5.2
The if statement [stmt.if]" (https://timsong-cpp.github.io/cppwp/stmt.if#1)

1 [...] If the first substatement is reached via a label, the condition
is not evaluated and the second substatement is not executed. [...]

--
Best regards,
Andrey

Re: Unglaublich, dass das funktioniert:

<20231222195041.415@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2948&group=comp.lang.c%2B%2B#2948

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Sat, 23 Dec 2023 04:07:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <20231222195041.415@kylheku.com>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Dec 2023 04:07:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="5000b185b96f3187e0e1564eb751772a";
logging-data="2047110"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+0t6skZXj5AYPqPOqwr8/FpAEIlOvgWA="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:SBsKFZUghBbcBLYHHohaw42MPj0=
 by: Kaz Kylheku - Sat, 23 Dec 2023 04:07 UTC

On 2023-12-21, Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
> On 12/17/23 5:27 AM, Bonita Montero wrote:
>> int main( int argc, char ** )
>> {
>>     switch( argc )
>>     {
>>         for( ; ; )
>>         {
>>         case 1:;
>>         }
>>     }
>> }
>>
>
> Meh... An old example of break-less switch-case branching
>
> #include <iostream>
>
> int main(int argc, char **)
> {
> switch (argc)
> if (0) case 1: std::cout << 1 << std::endl;
> else if (0) case 2: std::cout << 2 << std::endl;
> else if (0) case 3: std::cout << 3 << std::endl;
> else if (0) default: std::cout << "whatever" << std::endl;
> }

> As illustrated above, even if the body of switch is not enclosed into `{
> ... }`, one can still stuff a lot into a single protracted statement,
> including multiple `case` labels.

Why would you ever do this instead of just break?

It has the advantage that the protractive statement can be built up
catenatively, via macros, and no balancing closing macro is required.

Like with this this translation scheme. Macros on the left, generated
code right:

CASE(x) -> switch (x) if (0) { }
OF(1) -> else if (0) case (1):
{ ... code ...} -> { ... code ... }
OF(2) -> else if (0) case (1):
{ ... code ...} -> { ... code ... }
OTHERWISE -> else if (0) default:
{ ... code ...} -> { ... code ... }

(The programmer has to be careful not to put a stray else statement
after this, due to the hidden if.)

If we wanted to use break, we'd need to open a compound statement after
the switch, which would have to be closed by a pairing closing macro.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Unglaublich, dass das funktioniert:

<um6c0c$29v5$1@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2949&group=comp.lang.c%2B%2B#2949

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!pasdenom.info!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Sat, 23 Dec 2023 10:15:40 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <um6c0c$29v5$1@nyheter.lysator.liu.se>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me>
<um3trt$1hp7$3@nyheter.lysator.liu.se>
<um3v6n$1hp7$4@nyheter.lysator.liu.se> <um5dih$1pfu5$2@dont-email.me>
Injection-Date: Sat, 23 Dec 2023 10:15:40 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="75749"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Sat, 23 Dec 2023 10:15 UTC

Den 2023-12-23 skrev Andrey Tarasevich <andreytarasevich@hotmail.com>:
> On 12/22/23 4:24 AM, Andreas Kempe wrote:
>>
>> After thinking some more, I relise I don't know if my fallthrough idea
>> holds water considering the else if construct. The first statement is
>> false so the second statement should be tested, but we're jumping into
>> the true branch, which if taken should prevent the other test from
>> happening. Does anyone have pointers to relevant parts of the standard
>> that handle this weirdness?
>
> Yes, the standard states it explicitly right at the beginning of "8.5.2
> The if statement [stmt.if]" (https://timsong-cpp.github.io/cppwp/stmt.if#1)
>
> 1 [...] If the first substatement is reached via a label, the condition
> is not evaluated and the second substatement is not executed. [...]
>

Thank you. It makes sense that GCC warns, but the wording in the
standard makes me think that all the selection parts of the if
statements should be considered unreachable since the code will always
reach the substatements through labels and never execute any of the
selection statements.

Re: Unglaublich, dass das funktioniert:

<877cl438l7.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2955&group=comp.lang.c%2B%2B#2955

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Sat, 23 Dec 2023 21:36:04 +0000
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <877cl438l7.fsf@bsb.me.uk>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me>
<um5dc9$1pfu5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="07872d8b1f5eafe9b63f932615909179";
logging-data="2346660"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DEPc2eQspZRwVU6cruGaofYFm//uOor8="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:HKtf35721Vk9+WeQ2wJTVuGmcj4=
sha1:uIK0fQIJK/o5RzVBuIDyAGIX4Ng=
X-BSB-Auth: 1.b8493da9a20331ca0944.20231223213604GMT.877cl438l7.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 23 Dec 2023 21:36 UTC

Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

> On 12/22/23 2:12 AM, Ralf Goertz wrote:
>> Am Thu, 21 Dec 2023 18:13:39 -0800
>> schrieb Andrey Tarasevich <andreytarasevich@hotmail.com>:
>>
>>> On 12/20/23 11:34 PM, Ralf Goertz wrote:
>>>> On Wed, 20 Dec 2023 22:56:24 -0800
>>>> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>>>>
>>>>> Meh... An old example of break-less switch-case branching
>>>>>
>>>>> #include <iostream>
>>>>>
>>>>> int main(int argc, char **)
>>>>> {
>>>>> switch (argc)
>>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>> else if (0) case 2: std::cout << 2 << std::endl;
>>>>> else if (0) case 3: std::cout << 3 << std::endl;
>>>>> else if (0) default: std::cout << "whatever" << std::endl;
>>>>> }
>>>>>
>>>>> As illustrated above, even if the body of switch is not enclosed
>>>>> into `{ ... }`, one can still stuff a lot into a single protracted
>>>>> statement, including multiple `case` labels.
>>>>
>>>> Interestingly enough, I get a warning with gcc:
>>>>
>>>> warning: statement will never be executed [-Wswitch-unreachable]
>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>
>>>> although of course I still see the output of “1” when the program is
>>>> called without arguments.
>>>
>>> The compiler complains specifically about the `if (0)` part, not
>>> about the part that outputs 1.
>> Hm, I obviously get that the `if (0)` condition can't ever be fulfilled,
>> but according to <https://en.cppreference.com/w/cpp/language/statements>
>> selection statements (1,2) the statement after the condition statement
>> is part of the if statement. So part of the if statement may still be
>> executed.
>
> This has absolutely nothing to do with the fulfillability of if's
> condition. You can replace `if (0)` with `if (1)` and you will still get
> the same warning. The properties of that `if` are completely beside the
> point here.

I don't find that to be the case. gcc complains about this if (0) being
unreachable:

switch (argc)
if (0) case 1: std::cout << 1 << "\n";

but not this one:

switch (argc)
if (1) case 1: std::cout << 1 << "\n";

> What matters is that the compiler sees some tangible code (i.e. not a no-op
> declaration, but something that can potentially generate executable
> instructions), which precedes the very first `case` label. That code is
> unreachable for obvious reasons, since `switch` will always jump over
> it. Hence the warning.

I suspect something more subtle is going on.

--
Ben.

Re: Unglaublich, dass das funktioniert:

<MT0iN.8177$IfLe.369@fx36.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2959&group=comp.lang.c%2B%2B#2959

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx36.iad.POSTED!not-for-mail
Subject: Re: Unglaublich, dass das funktioniert:
Newsgroups: comp.lang.c++
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me>
<um5dc9$1pfu5$1@dont-email.me> <877cl438l7.fsf@bsb.me.uk>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.18
MIME-Version: 1.0
In-Reply-To: <877cl438l7.fsf@bsb.me.uk>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 72
Message-ID: <MT0iN.8177$IfLe.369@fx36.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sun, 24 Dec 2023 20:54:04 UTC
Date: Sun, 24 Dec 2023 15:53:57 -0500
X-Received-Bytes: 3875
 by: Pavel - Sun, 24 Dec 2023 20:53 UTC

Ben Bacarisse wrote:
> Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
>
>> On 12/22/23 2:12 AM, Ralf Goertz wrote:
>>> Am Thu, 21 Dec 2023 18:13:39 -0800
>>> schrieb Andrey Tarasevich <andreytarasevich@hotmail.com>:
>>>
>>>> On 12/20/23 11:34 PM, Ralf Goertz wrote:
>>>>> On Wed, 20 Dec 2023 22:56:24 -0800
>>>>> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>>>>>
>>>>>> Meh... An old example of break-less switch-case branching
>>>>>>
>>>>>> #include <iostream>
>>>>>>
>>>>>> int main(int argc, char **)
>>>>>> {
>>>>>> switch (argc)
>>>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>>> else if (0) case 2: std::cout << 2 << std::endl;
>>>>>> else if (0) case 3: std::cout << 3 << std::endl;
>>>>>> else if (0) default: std::cout << "whatever" << std::endl;
>>>>>> }
>>>>>>
>>>>>> As illustrated above, even if the body of switch is not enclosed
>>>>>> into `{ ... }`, one can still stuff a lot into a single protracted
>>>>>> statement, including multiple `case` labels.
>>>>>
>>>>> Interestingly enough, I get a warning with gcc:
>>>>>
>>>>> warning: statement will never be executed [-Wswitch-unreachable]
>>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>>
>>>>> although of course I still see the output of “1” when the program is
>>>>> called without arguments.
>>>>
>>>> The compiler complains specifically about the `if (0)` part, not
>>>> about the part that outputs 1.
>>> Hm, I obviously get that the `if (0)` condition can't ever be fulfilled,
>>> but according to <https://en.cppreference.com/w/cpp/language/statements>
>>> selection statements (1,2) the statement after the condition statement
>>> is part of the if statement. So part of the if statement may still be
>>> executed.
>>
>> This has absolutely nothing to do with the fulfillability of if's
>> condition. You can replace `if (0)` with `if (1)` and you will still get
>> the same warning. The properties of that `if` are completely beside the
>> point here.
>
> I don't find that to be the case. gcc complains about this if (0) being
> unreachable:
>
> switch (argc)
> if (0) case 1: std::cout << 1 << "\n";
>
> but not this one:
>
> switch (argc)
> if (1) case 1: std::cout << 1 << "\n";
I think "if (1)" *is* equivalent to no-op here or, in AT's terms, cannot
"potentially generate executable instructions". I would say "there is no
code to reach hence there is no switch-unreachable warning".
>
>> What matters is that the compiler sees some tangible code (i.e. not a no-op
>> declaration, but something that can potentially generate executable
>> instructions), which precedes the very first `case` label. That code is
>> unreachable for obvious reasons, since `switch` will always jump over
>> it. Hence the warning.
>
> I suspect something more subtle is going on.
>

Re: Unglaublich, dass das funktioniert:

<87y1dj1bt1.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=2961&group=comp.lang.c%2B%2B#2961

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Sun, 24 Dec 2023 22:21:46 +0000
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <87y1dj1bt1.fsf@bsb.me.uk>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org>
<um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me>
<um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me>
<um5dc9$1pfu5$1@dont-email.me> <877cl438l7.fsf@bsb.me.uk>
<MT0iN.8177$IfLe.369@fx36.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="b0d170afd13f8db6a424f4e6568c9778";
logging-data="2876470"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rAml2ZlMbp4EYdssc/6Mtkuw1l7/ISjQ="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:hwYAOrQywliSxhdaHlbfTEP1bS8=
sha1:Zx+r5J/0fkSUmCN+RY7jFp2U5PM=
X-BSB-Auth: 1.204a167e395c358ffd75.20231224222146GMT.87y1dj1bt1.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 24 Dec 2023 22:21 UTC

Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> writes:

> Ben Bacarisse wrote:
>> Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
>>
>>> On 12/22/23 2:12 AM, Ralf Goertz wrote:
>>>> Am Thu, 21 Dec 2023 18:13:39 -0800
>>>> schrieb Andrey Tarasevich <andreytarasevich@hotmail.com>:
>>>>
>>>>> On 12/20/23 11:34 PM, Ralf Goertz wrote:
>>>>>> On Wed, 20 Dec 2023 22:56:24 -0800
>>>>>> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>>>>>>
>>>>>>> Meh... An old example of break-less switch-case branching
>>>>>>>
>>>>>>> #include <iostream>
>>>>>>>
>>>>>>> int main(int argc, char **)
>>>>>>> {
>>>>>>> switch (argc)
>>>>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>>>> else if (0) case 2: std::cout << 2 << std::endl;
>>>>>>> else if (0) case 3: std::cout << 3 << std::endl;
>>>>>>> else if (0) default: std::cout << "whatever" << std::endl;
>>>>>>> }
>>>>>>>
>>>>>>> As illustrated above, even if the body of switch is not enclosed
>>>>>>> into `{ ... }`, one can still stuff a lot into a single protracted
>>>>>>> statement, including multiple `case` labels.
>>>>>>
>>>>>> Interestingly enough, I get a warning with gcc:
>>>>>>
>>>>>> warning: statement will never be executed [-Wswitch-unreachable]
>>>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>>>
>>>>>> although of course I still see the output of “1” when the program is
>>>>>> called without arguments.
>>>>>
>>>>> The compiler complains specifically about the `if (0)` part, not
>>>>> about the part that outputs 1.
>>>> Hm, I obviously get that the `if (0)` condition can't ever be fulfilled,
>>>> but according to <https://en.cppreference.com/w/cpp/language/statements>
>>>> selection statements (1,2) the statement after the condition statement
>>>> is part of the if statement. So part of the if statement may still be
>>>> executed.
>>>
>>> This has absolutely nothing to do with the fulfillability of if's
>>> condition. You can replace `if (0)` with `if (1)` and you will still get
>>> the same warning. The properties of that `if` are completely beside the
>>> point here.
>> I don't find that to be the case. gcc complains about this if (0) being
>> unreachable:
>> switch (argc)
>> if (0) case 1: std::cout << 1 << "\n";
>> but not this one:
>> switch (argc)
>> if (1) case 1: std::cout << 1 << "\n";
> I think "if (1)" *is* equivalent to no-op here or, in AT's terms, cannot
> "potentially generate executable instructions". I would say "there is no
> code to reach hence there is no switch-unreachable warning".

Sounds reasonable.

--
Ben.

Re: Unglaublich, dass das funktioniert:

<86jzout3es.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3012&group=comp.lang.c%2B%2B#3012

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c++
Subject: Re: Unglaublich, dass das funktioniert:
Date: Sun, 31 Dec 2023 14:26:03 -0800
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <86jzout3es.fsf@linuxsc.com>
References: <ulmt0o$2urci$1@raubtier-asyl.eternal-september.org> <um0niq$vqs2$1@dont-email.me> <um0pph$100f7$1@dont-email.me> <um2rck$19qhc$1@dont-email.me> <um3nea$1h1gc$1@dont-email.me> <um5dc9$1pfu5$1@dont-email.me> <877cl438l7.fsf@bsb.me.uk> <MT0iN.8177$IfLe.369@fx36.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="5ace88928e20b7842ad42526ffee8c84";
logging-data="1974666"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qXdQjQkN9yZVoEsgNXprefInCegNTm2M="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:9dxdLUb/uSA0tXsF4phIv/apPOg=
sha1:MamlME0cc/AvBspTcjwly/KlAWY=
 by: Tim Rentsch - Sun, 31 Dec 2023 22:26 UTC

Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> writes:

> Ben Bacarisse wrote:
>
>> Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
>>
>>> On 12/22/23 2:12 AM, Ralf Goertz wrote:
>>>
>>>> Am Thu, 21 Dec 2023 18:13:39 -0800
>>>> schrieb Andrey Tarasevich <andreytarasevich@hotmail.com>:
>>>>
>>>>> On 12/20/23 11:34 PM, Ralf Goertz wrote:
>>>>>
>>>>>> On Wed, 20 Dec 2023 22:56:24 -0800
>>>>>> Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>>>>>> >>>>>> Meh... An old example of break-less switch-case branching
>>>>>>
>>>>>>> #include <iostream>
>>>>>>>
>>>>>>> int main(int argc, char **)
>>>>>>> {
>>>>>>> switch (argc)
>>>>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>>>> else if (0) case 2: std::cout << 2 << std::endl;
>>>>>>> else if (0) case 3: std::cout << 3 << std::endl;
>>>>>>> else if (0) default: std::cout << "whatever" << std::endl;
>>>>>>> }
>>>>>>>
>>>>>>> As illustrated above, even if the body of switch is not enclosed
>>>>>>> into `{ ... }`, one can still stuff a lot into a single protracted
>>>>>>> statement, including multiple `case` labels.
>>>>>>
>>>>>> Interestingly enough, I get a warning with gcc:
>>>>>>
>>>>>> warning: statement will never be executed [-Wswitch-unreachable]
>>>>>> if (0) case 1: std::cout << 1 << std::endl;
>>>>>>
>>>>>> although of course I still see the output of ?1? when the program is
>>>>>> called without arguments.
>>>>>
>>>>> The compiler complains specifically about the `if (0)` part, not
>>>>> about the part that outputs 1.
>>>>
>>>> Hm, I obviously get that the `if (0)` condition can't ever be fulfilled,
>>>> but according to <https://en.cppreference.com/w/cpp/language/statements>
>>>> selection statements (1,2) the statement after the condition statement
>>>> is part of the if statement. So part of the if statement may still be
>>>> executed.
>>>
>>> This has absolutely nothing to do with the fulfillability of if's
>>> condition. You can replace `if (0)` with `if (1)` and you will still get
>>> the same warning. The properties of that `if` are completely beside the
>>> point here.
>>
>> I don't find that to be the case. gcc complains about this if (0) being
>> unreachable:
>>
>> switch (argc)
>> if (0) case 1: std::cout << 1 << "\n";
>>
>> but not this one:
>>
>> switch (argc)
>> if (1) case 1: std::cout << 1 << "\n";
>
> I think "if (1)" *is* equivalent to no-op here or, in AT's terms,
> cannot "potentially generate executable instructions". I would say
> "there is no code to reach hence there is no switch-unreachable
> warning".

Some compilers complain. Other don't.

I've seen the 'if(1)' version get a warning, and not get a
warning with a different compiler.

I've seen a 'for(;0;) case 1: ...' get a warning in some
circumstances, and not in others.

I tried some other variations, and got various results
under different compilers.

I'm reminded of Abraham Lincoln's review: "For people who
like this sort of thing, this is the sort of thing that
those people like."


devel / comp.lang.c++ / Re: Unglaublich, dass das funktioniert:

Pages:12
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor