diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 79697a2e6d7..e221accc782 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1941,17 +1941,7 @@ static bool isConstPointerVariable(const Variable* p, const Settings& settings) namespace { struct CompareVariables { bool operator()(const Variable* a, const Variable* b) const { - const int fileA = a->nameToken()->fileIndex(); - const int fileB = b->nameToken()->fileIndex(); - if (fileA != fileB) - return fileA < fileB; - const int lineA = a->nameToken()->linenr(); - const int lineB = b->nameToken()->linenr(); - if (lineA != lineB) - return lineA < lineB; - const int columnA = a->nameToken()->column(); - const int columnB = b->nameToken()->column(); - return columnA < columnB; + return precedes(a->nameToken(), b->nameToken()); } }; } diff --git a/test/testother.cpp b/test/testother.cpp index d6025e9a640..085b39cfffb 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5087,6 +5087,15 @@ class TestOther : public TestFixture { "void g(__attribute__((unused)) int *p) {}\n" "void h(int *p) {}\n"); ASSERT_EQUALS("[test.cpp:3:13]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str()); + + checkP("struct S { int i; };\n" // #15222 + "#define DECL_ARGS S *p, S *q\n" + "void f(DECL_ARGS) {\n" + " if (p->i == 0 && q->i == 1) {}\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:8]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n" + "[test.cpp:3:8]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n", + errout_str()); } void constArray() {