From 8b43d84738c5c47dcc6644beb42f4ac4799ccff4 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 31 Jan 2022 14:56:31 +0100 Subject: [PATCH 1/5] Fix #10679 FP constParameter with const/nonconst overload --- lib/symboldatabase.cpp | 8 ++++++-- test/testother.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a3d3e7c7233..c3259bf12da 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -7093,8 +7093,12 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va return ValueType::MatchResult::FALLBACK2; return ValueType::MatchResult::NOMATCH; // TODO } - if (call->pointer > 0 && ((call->constness | func->constness) != func->constness)) - return ValueType::MatchResult::NOMATCH; + if (call->pointer > 0) { + if ((call->constness | func->constness) != func->constness) + return ValueType::MatchResult::NOMATCH; + if (call->constness != func->constness && call->reference != func->reference && func->reference != Reference::None) + return ValueType::MatchResult::NOMATCH; + } if (call->type != func->type) { if (call->type == ValueType::Type::VOID || func->type == ValueType::Type::VOID) return ValueType::MatchResult::FALLBACK1; diff --git a/test/testother.cpp b/test/testother.cpp index 698275c3c37..1e937238362 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2654,6 +2654,16 @@ class TestOther : public TestFixture { " void f(Foo& foo) const { int* q = foo.get(); *q = j; }\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + check("struct S {\n" // #10679 + " void g(long L, const C*& PC) const;\n" + " void g(long L, C*& PC);\n" + "};\n" + "void f(S& s) {\n" + " C* PC{};\n" + " s.g(0, PC);\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void constParameterCallback() { From 428b6c03a1233c94141388a558bd4a50c1cba32e Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 31 Jan 2022 15:03:39 +0100 Subject: [PATCH 2/5] Format --- lib/symboldatabase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c3259bf12da..e3ef3c235bd 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -7094,10 +7094,10 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va return ValueType::MatchResult::NOMATCH; // TODO } if (call->pointer > 0) { - if ((call->constness | func->constness) != func->constness) - return ValueType::MatchResult::NOMATCH; - if (call->constness != func->constness && call->reference != func->reference && func->reference != Reference::None) - return ValueType::MatchResult::NOMATCH; + if ((call->constness | func->constness) != func->constness) + return ValueType::MatchResult::NOMATCH; + if (call->constness != func->constness && call->reference != func->reference && func->reference != Reference::None) + return ValueType::MatchResult::NOMATCH; } if (call->type != func->type) { if (call->type == ValueType::Type::VOID || func->type == ValueType::Type::VOID) From cff45e017da0abf7fe2d1ddac5c28925695c4a94 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 31 Jan 2022 15:38:23 +0100 Subject: [PATCH 3/5] Check for reference to const pointer --- lib/symboldatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e3ef3c235bd..d4cd002ba5c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -7096,7 +7096,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va if (call->pointer > 0) { if ((call->constness | func->constness) != func->constness) return ValueType::MatchResult::NOMATCH; - if (call->constness != func->constness && call->reference != func->reference && func->reference != Reference::None) + if (call->constness == 0 && func->constness != 0 && func->reference != Reference::None) return ValueType::MatchResult::NOMATCH; } if (call->type != func->type) { From 68acdb397243ee792bb415411d4d188966dfc384 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 31 Jan 2022 15:38:39 +0100 Subject: [PATCH 4/5] Format --- test/testclass.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/testclass.cpp b/test/testclass.cpp index 66b0ed4b5ce..72689b8848c 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6725,12 +6725,11 @@ class TestClass : public TestFixture { " void f(const char* const (&StrArr)[N]);\n" "};\n" "template\n" - "void S::f(const std::array&sv) {\n" + "void S::f(const std::array& sv) {\n" " const char* ptrs[N]{};\n" " return f(ptrs);\n" "}\n" - "template void S::f(const std::array&sv);\n" - "\n"); + "template void S::f(const std::array& sv);\n"); ASSERT_EQUALS("", errout.str()); } From 8f96eac1ec266fc548fe5c5f5133fb5248381352 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 31 Jan 2022 16:38:01 +0100 Subject: [PATCH 5/5] knownConditionTrueFalse --- lib/symboldatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index d4cd002ba5c..72b4106a487 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -7102,7 +7102,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va if (call->type != func->type) { if (call->type == ValueType::Type::VOID || func->type == ValueType::Type::VOID) return ValueType::MatchResult::FALLBACK1; - if (call->pointer > 0 && func->pointer > 0) + if (call->pointer > 0) return func->type == ValueType::UNKNOWN_TYPE ? ValueType::MatchResult::UNKNOWN : ValueType::MatchResult::NOMATCH; if (call->isIntegral() && func->isIntegral()) return call->type < func->type ?