File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1939,6 +1939,8 @@ void CheckOther::checkConstPointer()
19391939 const Token* gparent = parent->astParent ();
19401940 while (Token::simpleMatch (gparent, " [" ) && parent != gparent->astOperand2 () && parent->str () == gparent->str ())
19411941 gparent = gparent->astParent ();
1942+ while (Token::Match (gparent, " [?:]" ))
1943+ gparent = gparent->astParent ();
19421944 if (deref == MEMBER) {
19431945 if (!gparent)
19441946 continue ;
Original file line number Diff line number Diff line change @@ -4823,6 +4823,20 @@ class TestOther : public TestFixture {
48234823 " return s->x ? 1 : 0;\n"
48244824 "}\n");
48254825 ASSERT_EQUALS("[test.cpp:2:10]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str());
4826+
4827+ check("int f(int *p, int *q) {\n" // #14748
4828+ " return p ? *p : *q;\n"
4829+ "}\n"
4830+ "void g(int *p, int *q) {\n"
4831+ " int& r = p ? *p : *q;\n"
4832+ " r = 0;\n"
4833+ "}\n"
4834+ "void h(int *p, int *q) {\n"
4835+ " i(p ? *p : *q);\n"
4836+ "}\n");
4837+ ASSERT_EQUALS("[test.cpp:1:12]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n"
4838+ "[test.cpp:1:20]: (style) Parameter 'q' can be declared as pointer to const [constParameterPointer]\n",
4839+ errout_str());
48264840 }
48274841
48284842 void constArray() {
You can’t perform that action at this time.
0 commit comments