Fix FP functionConst with ternary (#4874)
This commit is contained in:
parent
3db05cf3a4
commit
a5b0fd38fd
|
@ -2347,6 +2347,10 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
|
||||||
const Token* lhs = tok1->previous();
|
const Token* lhs = tok1->previous();
|
||||||
if (lhs->str() == "(" && tok1->astParent() && tok1->astParent()->astParent())
|
if (lhs->str() == "(" && tok1->astParent() && tok1->astParent()->astParent())
|
||||||
lhs = tok1->astParent()->astParent();
|
lhs = tok1->astParent()->astParent();
|
||||||
|
else if (lhs->str() == "?" && lhs->astParent())
|
||||||
|
lhs = lhs->astParent();
|
||||||
|
else if (lhs->str() == ":" && lhs->astParent() && lhs->astParent()->astParent() && lhs->astParent()->str() == "?")
|
||||||
|
lhs = lhs->astParent()->astParent();
|
||||||
if (lhs->str() == "&") {
|
if (lhs->str() == "&") {
|
||||||
lhs = lhs->previous();
|
lhs = lhs->previous();
|
||||||
if (lhs->isAssignmentOp() && lhs->previous()->variable()) {
|
if (lhs->isAssignmentOp() && lhs->previous()->variable()) {
|
||||||
|
|
|
@ -195,6 +195,7 @@ private:
|
||||||
TEST_CASE(const79); // ticket #9861
|
TEST_CASE(const79); // ticket #9861
|
||||||
TEST_CASE(const80); // ticket #11328
|
TEST_CASE(const80); // ticket #11328
|
||||||
TEST_CASE(const81); // ticket #11330
|
TEST_CASE(const81); // ticket #11330
|
||||||
|
TEST_CASE(const82);
|
||||||
TEST_CASE(const_handleDefaultParameters);
|
TEST_CASE(const_handleDefaultParameters);
|
||||||
TEST_CASE(const_passThisToMemberOfOtherClass);
|
TEST_CASE(const_passThisToMemberOfOtherClass);
|
||||||
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
|
TEST_CASE(assigningPointerToPointerIsNotAConstOperation);
|
||||||
|
@ -6321,6 +6322,23 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void const82() {
|
||||||
|
checkConst("struct S {\n"
|
||||||
|
" int i1, i2;\n"
|
||||||
|
" void f(bool b);\n"
|
||||||
|
" void g(bool b, int j);\n"
|
||||||
|
"};\n"
|
||||||
|
"void S::f(bool b) {\n"
|
||||||
|
" int& r = b ? i1 : i2;\n"
|
||||||
|
" r = 5;\n"
|
||||||
|
"}\n"
|
||||||
|
"void S::g(bool b, int j) {\n"
|
||||||
|
" int& r = b ? j : i2;\n"
|
||||||
|
" r = 5;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void const_handleDefaultParameters() {
|
void const_handleDefaultParameters() {
|
||||||
checkConst("struct Foo {\n"
|
checkConst("struct Foo {\n"
|
||||||
" void foo1(int i, int j = 0) {\n"
|
" void foo1(int i, int j = 0) {\n"
|
||||||
|
|
Loading…
Reference in New Issue