Community
Participate
Working Groups
Build Identifier: Combined declaration and initialisation in a switch statement is not allowed if the scope is not changed. This is because each of the 'case' entries in the switch represents a label. This means you can jump over the statements in a case, which is not allowed for declaration + initialization (see C++ 2003, 6.7-3). The solution is to add a new scope in the case. Error case: switch(a) { case 0: int j = 2; <-- error default: break; } Working case: switch(a) { case 0: { int j = 2; } default: break; } Reproducible: Always
Created attachment 256793 [details] Added a new CDT Codan checker for this semantic error
Created attachment 256794 [details] Added a test unit for the InitializationInCaseChecker
Thanks for writing a patch and test, Sarah! Could you submit them for review via Gerrit as described here [1]? [1] https://wiki.eclipse.org/CDT/git#Using_Gerrit_for_CDT
Hello Nathan. I'll make sure I set everything up and submit them for review on Gerrit
Created attachment 256929 [details] Fix issue in the InitializationInCaseChecker
Created attachment 256930 [details] Add more test cases
New Gerrit change created: https://git.eclipse.org/r/57362
Sarah, thank you for submitting the patch to Gerrit. I saw Elena reviewed it and had some review comments; do you plan to address them?