Fix regression: functionStatic related to overload resolution (#3705)

This commit is contained in:
chrchr-github 2022-01-14 17:55:50 +01:00 committed by GitHub
parent 12abf85d1d
commit 781a145680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -7094,9 +7094,10 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
{ {
ValueType vt; ValueType vt;
const ValueType* pvt = funcVar->valueType(); const ValueType* pvt = funcVar->valueType();
if (pvt && funcVar->isArray()) { if (pvt && funcVar->isArray() && !(funcVar->isStlType() && Token::simpleMatch(funcVar->typeStartToken(), "std :: array"))) { // std::array doesn't decay to a pointer
vt = *pvt; vt = *pvt;
++vt.pointer; if (vt.pointer == 0) // don't bump array of pointers
++vt.pointer;
pvt = &vt; pvt = &vt;
} }
ValueType::MatchResult res = ValueType::matchParameter(call, pvt); ValueType::MatchResult res = ValueType::matchParameter(call, pvt);

View File

@ -201,6 +201,7 @@ private:
TEST_CASE(const_shared_ptr); TEST_CASE(const_shared_ptr);
TEST_CASE(constPtrToConstPtr); TEST_CASE(constPtrToConstPtr);
TEST_CASE(constTrailingReturnType); TEST_CASE(constTrailingReturnType);
TEST_CASE(staticArrayPtrOverload);
TEST_CASE(initializerListOrder); TEST_CASE(initializerListOrder);
TEST_CASE(initializerListUsage); TEST_CASE(initializerListUsage);
@ -6569,6 +6570,23 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void staticArrayPtrOverload() {
checkConst("struct S {\n"
" template<size_t N>\n"
" void f(const std::array<std::string_view, N>& sv);\n"
" template<long N>\n"
" void f(const char* const (&StrArr)[N]);\n"
"};\n"
"template<size_t N>\n"
"void S::f(const std::array<std::string_view, N>&sv) {\n"
" const char* ptrs[N]{};\n"
" return f(ptrs);\n"
"}\n"
"template void S::f(const std::array<std::string_view, 3>&sv);\n"
"\n");
ASSERT_EQUALS("", errout.str());
}
#define checkInitializerListOrder(code) checkInitializerListOrder_(code, __FILE__, __LINE__) #define checkInitializerListOrder(code) checkInitializerListOrder_(code, __FILE__, __LINE__)
void checkInitializerListOrder_(const char code[], const char* file, int line) { void checkInitializerListOrder_(const char code[], const char* file, int line) {
// Clear the error log // Clear the error log