From 511520d6236c7b8b9cb77ed7d259a5438c6c05c9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 2 Feb 2022 19:38:32 +0100 Subject: [PATCH] Fix #10679 FP constParameter with const/nonconst overload (#3780) --- lib/symboldatabase.cpp | 10 +++++++--- test/testclass.cpp | 5 ++--- test/testother.cpp | 10 ++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b9b1f5077..31e8c44f7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -7098,12 +7098,16 @@ 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 == 0 && func->constness != 0 && 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; - 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 ? diff --git a/test/testclass.cpp b/test/testclass.cpp index 3f0aef3d0..ce573da78 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -6744,12 +6744,11 @@ private: " 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()); } diff --git a/test/testother.cpp b/test/testother.cpp index 0acbdfcc2..00faf3372 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2666,6 +2666,16 @@ private: " 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() {