Skip to content

Commit 511520d

Browse files
Fix #10679 FP constParameter with const/nonconst overload (#3780)
1 parent 2cacb13 commit 511520d

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7098,12 +7098,16 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
70987098
return ValueType::MatchResult::FALLBACK2;
70997099
return ValueType::MatchResult::NOMATCH; // TODO
71007100
}
7101-
if (call->pointer > 0 && ((call->constness | func->constness) != func->constness))
7102-
return ValueType::MatchResult::NOMATCH;
7101+
if (call->pointer > 0) {
7102+
if ((call->constness | func->constness) != func->constness)
7103+
return ValueType::MatchResult::NOMATCH;
7104+
if (call->constness == 0 && func->constness != 0 && func->reference != Reference::None)
7105+
return ValueType::MatchResult::NOMATCH;
7106+
}
71037107
if (call->type != func->type) {
71047108
if (call->type == ValueType::Type::VOID || func->type == ValueType::Type::VOID)
71057109
return ValueType::MatchResult::FALLBACK1;
7106-
if (call->pointer > 0 && func->pointer > 0)
7110+
if (call->pointer > 0)
71077111
return func->type == ValueType::UNKNOWN_TYPE ? ValueType::MatchResult::UNKNOWN : ValueType::MatchResult::NOMATCH;
71087112
if (call->isIntegral() && func->isIntegral())
71097113
return call->type < func->type ?

test/testclass.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6744,12 +6744,11 @@ class TestClass : public TestFixture {
67446744
" void f(const char* const (&StrArr)[N]);\n"
67456745
"};\n"
67466746
"template<size_t N>\n"
6747-
"void S::f(const std::array<std::string_view, N>&sv) {\n"
6747+
"void S::f(const std::array<std::string_view, N>& sv) {\n"
67486748
" const char* ptrs[N]{};\n"
67496749
" return f(ptrs);\n"
67506750
"}\n"
6751-
"template void S::f(const std::array<std::string_view, 3>&sv);\n"
6752-
"\n");
6751+
"template void S::f(const std::array<std::string_view, 3>& sv);\n");
67536752
ASSERT_EQUALS("", errout.str());
67546753
}
67556754

test/testother.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,16 @@ class TestOther : public TestFixture {
26662666
" void f(Foo& foo) const { int* q = foo.get(); *q = j; }\n"
26672667
"};\n");
26682668
ASSERT_EQUALS("", errout.str());
2669+
2670+
check("struct S {\n" // #10679
2671+
" void g(long L, const C*& PC) const;\n"
2672+
" void g(long L, C*& PC);\n"
2673+
"};\n"
2674+
"void f(S& s) {\n"
2675+
" C* PC{};\n"
2676+
" s.g(0, PC);\n"
2677+
"};\n");
2678+
ASSERT_EQUALS("", errout.str());
26692679
}
26702680

26712681
void constParameterCallback() {

0 commit comments

Comments
 (0)