Fix #10679 FP constParameter with const/nonconst overload (#3780)

This commit is contained in:
chrchr-github 2022-02-02 19:38:32 +01:00 committed by GitHub
parent 2cacb13f85
commit 511520d623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View File

@ -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))
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 ?

View File

@ -6748,8 +6748,7 @@ private:
" const char* ptrs[N]{};\n"
" return f(ptrs);\n"
"}\n"
"template void S::f(const std::array<std::string_view, 3>&sv);\n"
"\n");
"template void S::f(const std::array<std::string_view, 3>& sv);\n");
ASSERT_EQUALS("", errout.str());
}

View File

@ -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() {