Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analysis error on explicit case fall-through #19101

Open
dlangBugzillaToGithub opened this issue Feb 27, 2016 · 6 comments
Open

Analysis error on explicit case fall-through #19101

dlangBugzillaToGithub opened this issue Feb 27, 2016 · 6 comments

Comments

@dlangBugzillaToGithub
Copy link

Johan Engelen (@JohanEngelen) reported this on 2016-02-27T13:10:38Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=15731

CC List

  • Dennis
  • RazvanN

Description

The following code compiles fine without explicit fall-through, but with -version=bad it errors.

int hexStringConstant(dchar* p)
{
    while (1)
    {
        dchar c = *p++;
        switch (c)
        {
        case ' ':
        case '\t':
        case '\v':
        case '\f':
            continue;
        case '\r':
            if (*p == '
')
                continue;
            version(bad)      /// <-- Look here
              goto case;
        case '
':
            continue;
        case 0:
        case 0x1A:
            return 111;
        case '"':
            return 222;
        default:
            break;
        }
    }
}

> dmd -c bug.d
[ no problem ]

> dmd -c bug.d -w
bug.d(18): Warning: switch case fallthrough - use 'goto case;' if intended

> dmd -c bug.d -version=bad
bug.d(1): Error: function bug.hexStringConstant no return exp; or assert(0); at end of function
@dlangBugzillaToGithub
Copy link
Author

jbc.engelen (@JohanEngelen) commented on 2016-02-27T13:59:11Z

DMD version = 2.070.0

@dlangBugzillaToGithub
Copy link
Author

coolfool4 commented on 2018-10-28T08:09:55Z

I can't get errors nor warnings for fallthroughs except with final switches on enums (-w or -wi don't help).

Compiler versions:
- DMD64 D Compiler v2.082.0
- nightly at https://run.dlang.io/


import std.stdio;

void main() {
    int x = 0;
    switch (x) {
        case 0:
        case 1:
            writeln("woot");
            return;
        default:
    }
}

@dlangBugzillaToGithub
Copy link
Author

coolfool4 commented on 2018-10-28T08:25:35Z

Actually I don't get fallthrough warnings for *any* switches.

@dlangBugzillaToGithub
Copy link
Author

coolfool4 commented on 2018-10-28T08:28:38Z

So it seems to accept *empty* cases to fall through. I guess this is intended, then?

@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2022-11-03T10:09:28Z

When compiling the initial example I get:

test.d(18): Error: switch case fallthrough - use 'goto case;' if intended


This seems to have been fixed

@dlangBugzillaToGithub
Copy link
Author

dkorpel commented on 2022-11-03T10:22:18Z

(In reply to RazvanN from comment #5)
> When compiling the initial example I get:
> 
> test.d(18): Error: switch case fallthrough - use 'goto case;' if intended
> 
> 
> This seems to have been fixed

The problem is that with -version=bad, it incorrectly raises an error about missing a return statement or assert(0). That's still the case.

Here's a reduced example:
```
// accepts valid
int a()
{
    while (1)
    {
        switch (0)
        {
            case 0: // < implicit fallthrough
            default: continue;
        }
    }
}

// rejects valid
int b()
{
    while (1)
    {
        switch (0)
        {
            case 0: goto default; // < explicit fallthrough
            default: continue;
        }
    }
}
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant