Bug 443315 - "Expected expression" error declaring a variable immediately after a case label
Summary: "Expected expression" error declaring a variable immediately after a case label
Status: RESOLVED WORKSFORME
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: 5.6.2
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-04 17:28 UTC by Katalin Rebhan
Modified: 2021-11-03 04:35 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Katalin Rebhan 2021-10-04 17:28:45 UTC
SUMMARY

KDevelop analyzes a variable declaration right at the beginning of a case block incorrectly, leading to an error while the code still compiles.

Minimal reproducible case:

    // test.c
    int main()
    {
        switch (0) {
        case 0:
            int i;  // error: Expected expression
        }

        return 0;
    }

After changing this code to the following, the error goes away:

    // test.c
    int main()
    {
        switch (0) {
        case 0:
            0;        // <- inserted line, any statement will do
            int i;
        }

        return 0;
    }

STEPS TO REPRODUCE
1. Declare a variable immediately after a case label in a switch statement

OBSERVED RESULT
KDevelop will show an "Expected expression" error after the variable declaration

EXPECTED RESULT
KDevelop parses the code correctly as a variable declaration

SOFTWARE/OS VERSIONS
Operating System: Gentoo 2.8
KDE Plasma Version: 5.22.90
KDE Frameworks Version: 5.86.0
Qt Version: 5.15.2
Kernel Version: 5.14.8-gentoo-dist (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 5600X 6-Core Processor
Memory: 23.4 GiB of RAM
Graphics Processor: Radeon RX Vega

ADDITIONAL INFORMATION
Comment 1 Sven Brauch 2021-10-04 18:10:06 UTC
I can't reproduce this behavior. Are you sure parsing has actually finished after you changed the code? It's very unlikely that there is a bug here because parsing is handled by clang.
Comment 2 Katalin Rebhan 2021-10-04 18:30:29 UTC
Ah, I see. Yeah, parsing is finished and this persists across restarts of KDevelop, happens in multiple locations and also with a new project (Standard -> Terminal template).

It's probably a clang bug then, did you test it with clang 13.0.0?
Comment 3 Bug Janitor Service 2021-10-19 04:35:50 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 4 Bug Janitor Service 2021-11-03 04:35:32 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!