C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A draft for modern switch

From: Jeremy Rifkin <rifkin.jer_at_[hidden]>
Date: Tue, 20 May 2025 11:34:15 -0500
> I’d like to use switch instead of some new construct

Switch is a very thorny contraption, it's a remnant of an older time and
it's just not good language design. Switch cases falling through are
bug-prone and everyone runs into problems with "error: jump to case label
crosses initialization of xyz" etc. The mere notion of able to write
nonsense like the following is not a good thing:

switch(n) {
    while(n--) {
        case 10:
          foo(n);
        case 20:
          bar();
        default:;
    }
}

Switch will never go away, but we should move to something better.

Jeremy

On Tue, May 20, 2025 at 10:36 AM Filip via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> > `switch` should not be looked on as something that has a future.
>
> Maybe just a preference but I’d like to use switch instead of some new
> construct. Seems like an easy thing to do.
>
> Cheers, Filip
>
> Wiadomość napisana przez Jason McKesson via Std-Proposals <
> std-proposals_at_[hidden]> w dniu 20 maj 2025, o godz. 15:52:
>
> `switch` should not be looked on as something that has a future.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-05-20 16:34:29