@@ -1052,6 +1052,65 @@ class TestSuppressions : public TestFixture {
10521052 " a = DIV(10,1);\n " ,
10531053 " " );
10541054 ASSERT_EQUALS (" [test.cpp:2:1]: (information) Unmatched suppression: abc [unmatchedSuppression]\n " , errout_str ());
1055+
1056+ // #15208 - macro whose body is a single call to another macro
1057+ ASSERT_EQUALS (0 ,
1058+ (this ->*check)(" #define DIV(A,B) A/B\n "
1059+ " // cppcheck-suppress-macro zerodiv\n "
1060+ " #define ALIAS(A,B) DIV(A,B)\n "
1061+ " void f() {\n "
1062+ " int a = ALIAS(10,0);\n "
1063+ " }\n " ,
1064+ " " ));
1065+ ASSERT_EQUALS (" " , errout_str ());
1066+
1067+ // function-like macro name that is not expanded
1068+ ASSERT_EQUALS (1 ,
1069+ (this ->*check)(" // cppcheck-suppress-macro zerodiv\n "
1070+ " #define ALIAS(A,B) A/B\n "
1071+ " void f() {\n "
1072+ " int ALIAS = 1/0;\n "
1073+ " }\n " ,
1074+ " " ));
1075+ ASSERT_EQUALS (" [test.cpp:4:18]: (error) Division by zero. [zerodiv]\n "
1076+ " [test.cpp:2:1]: (information) Unmatched suppression: zerodiv [unmatchedSuppression]\n " , errout_str ());
1077+
1078+ // empty macro on the line
1079+ ASSERT_EQUALS (1 ,
1080+ (this ->*check)(" // cppcheck-suppress-macro zerodiv\n "
1081+ " #define EMPTY\n "
1082+ " void f() {\n "
1083+ " EMPTY int a = 1/0;\n "
1084+ " }\n " ,
1085+ " " ));
1086+ ASSERT_EQUALS (" [test.cpp:4:20]: (error) Division by zero. [zerodiv]\n "
1087+ " [test.cpp:2:1]: (information) Unmatched suppression: zerodiv [unmatchedSuppression]\n " , errout_str ());
1088+
1089+ // macro expanded on a line where its name is also a plain identifier
1090+ ASSERT_EQUALS (0 ,
1091+ (this ->*check)(" #define DIV(A,B) A/B\n "
1092+ " // cppcheck-suppress-macro zerodiv\n "
1093+ " #define ALIAS(A,B) DIV(A,B)\n "
1094+ " struct S { int ALIAS; };\n "
1095+ " int f(struct S s) {\n "
1096+ " return ALIAS(1,0) + s.ALIAS;\n "
1097+ " }\n " ,
1098+ " " ));
1099+ ASSERT_EQUALS (" " , errout_str ());
1100+
1101+ // TODO: simplecpp only reports the usages of macros that are defined when preprocessing ends
1102+ TODO_ASSERT_EQUALS (0 , 1 ,
1103+ (this ->*check)(" #define DIV(A,B) A/B\n "
1104+ " // cppcheck-suppress-macro zerodiv\n "
1105+ " #define ALIAS(A,B) DIV(A,B)\n "
1106+ " void f() {\n "
1107+ " int a = ALIAS(1,0);\n "
1108+ " }\n "
1109+ " #undef ALIAS\n " ,
1110+ " " ));
1111+ TODO_ASSERT_EQUALS (" " ,
1112+ " [test.cpp:5:13]: (error) Division by zero. [zerodiv]\n "
1113+ " [test.cpp:3:1]: (information) Unmatched suppression: zerodiv [unmatchedSuppression]\n " , errout_str ());
10551114 }
10561115
10571116 void suppressionsSettingsFiles () {
0 commit comments