Skip to content

Commit 2d3487b

Browse files
Fix #15222 FN constParameterPointer (parameters declared in macro) (#9032)
1 parent 376ebd7 commit 2d3487b

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

‎lib/checkother.cpp‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,17 +1941,7 @@ static bool isConstPointerVariable(const Variable* p, const Settings& settings)
19411941
namespace {
19421942
struct CompareVariables {
19431943
bool operator()(const Variable* a, const Variable* b) const {
1944-
const int fileA = a->nameToken()->fileIndex();
1945-
const int fileB = b->nameToken()->fileIndex();
1946-
if (fileA != fileB)
1947-
return fileA < fileB;
1948-
const int lineA = a->nameToken()->linenr();
1949-
const int lineB = b->nameToken()->linenr();
1950-
if (lineA != lineB)
1951-
return lineA < lineB;
1952-
const int columnA = a->nameToken()->column();
1953-
const int columnB = b->nameToken()->column();
1954-
return columnA < columnB;
1944+
return precedes(a->nameToken(), b->nameToken());
19551945
}
19561946
};
19571947
}

‎test/testother.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5087,6 +5087,15 @@ class TestOther : public TestFixture {
50875087
"void g(__attribute__((unused)) int *p) {}\n"
50885088
"void h(int *p) {}\n");
50895089
ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str());
5090+
5091+
checkP("struct S { int i; };\n" // #15222
5092+
"#define DECL_ARGS S *p, S *q\n"
5093+
"void f(DECL_ARGS) {\n"
5094+
" if (p->i == 0 && q->i == 1) {}\n"
5095+
"}\n");
5096+
ASSERT_EQUALS("[test.cpp:3:8]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n"
5097+
"[test.cpp:3:8]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n",
5098+
errout_str());
50905099
}
50915100

50925101
void constArray() {

0 commit comments

Comments
 (0)