Merge pull request #1237 from geoffw0/commentedoutcode2

CPP: Fix FPs from detecting commented out preprocessor logic
This commit is contained in:
Robert Marsh
2019-04-16 10:31:42 -07:00
committed by GitHub
6 changed files with 132 additions and 9 deletions

View File

@@ -8,6 +8,11 @@
| test2.cpp:63:1:63:15 | // #pragma once | This comment appears to contain commented-out code |
| test2.cpp:65:1:65:17 | // # pragma once | This comment appears to contain commented-out code |
| test2.cpp:67:1:67:19 | /*#error"myerror"*/ | This comment appears to contain commented-out code |
| test2.cpp:91:1:95:2 | /*\n#ifdef MYMACRO\n\t// ...\n#endif // #ifdef MYMACRO\n*/ | This comment appears to contain commented-out code |
| test2.cpp:107:21:107:43 | // #include "config2.h" | This comment appears to contain commented-out code |
| test2.cpp:115:16:115:35 | /* #ifdef MYMACRO */ | This comment appears to contain commented-out code |
| test2.cpp:117:1:117:24 | // commented_out_code(); | This comment appears to contain commented-out code |
| test2.cpp:120:2:120:25 | // commented_out_code(); | This comment appears to contain commented-out code |
| test.c:2:1:2:22 | // commented out code; | This comment appears to contain commented-out code |
| test.c:4:1:7:8 | // some; | This comment appears to contain commented-out code |
| test.c:9:1:13:8 | // also; | This comment appears to contain commented-out code |

View File

@@ -0,0 +1,19 @@
/* define if you want setting 1 */
#define SETTING1
// define if you want setting 2
//#define SETTING2
/* define if you want setting 3 */
//#define SETTING3
/* define if you want setting 4 */
/* #define SETTING4 */
#if defined(SETTING3) && defined(SETTING4)
#error "can't have both SETTING3 and SETTING4"
#endif
/* uncomment if you don't want setting 5 */
/* #undef SETTING5 */

View File

@@ -65,3 +65,57 @@ void myFunction();
// # pragma once
/*#error"myerror"*/
#ifdef MYMACRO
// ...
#endif // #ifdef MYMACRO
#if !defined(MYMACRO)
// ...
#else // #if !defined(MYMACRO)
// ...
#endif // #else #if !defined(MYMACRO)
#ifdef MYMACRO
// ...
#endif // #ifdef MYMACRO (comment)
/*
#ifdef MYMACRO
// ...
#endif // #ifdef MYMACRO
*/
#ifdef MYMACRO1
#ifdef MYMACRO2
// ...
// comment at end of block
#endif // #ifdef MYMACRO2
#endif // #ifdef MYMACRO1
#include "config.h" // #include "config2.h"
#ifdef MYMACRO
// ...
#endif /* #ifdef MYMACRO */
#error "error" /* #ifdef MYMACRO */
// commented_out_code();
#if 0
// commented_out_code();
#endif