Fix #10304: std::distance() returns std::ptrdiff_t (#3297)

This commit is contained in:
chrchr-github 2021-06-24 23:19:29 +02:00 committed by GitHub
parent 769b20b426
commit 39f9bc7422
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -7204,7 +7204,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
<!-- template<class InputIterator> typename iterator_traits<InputIterator>::difference_type std::distance (InputIterator first, InputIterator last); -->
<function name="std::distance">
<use-retval/>
<returnValue type="std::ssize_t"/>
<returnValue type="std::ptrdiff_t"/>
<noreturn>false</noreturn>
<arg nr="1" direction="in">
<not-uninit/>

View File

@ -74,6 +74,7 @@ private:
TEST_CASE(testPrintfTypeAlias1);
TEST_CASE(testPrintfAuto); // #8992
TEST_CASE(testPrintfParenthesis); // #8489
TEST_CASE(testStdDistance); // #10304
}
void check(const char* code, bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified, bool onlyFormatStr = false) {
@ -4819,6 +4820,14 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", errout.str());
}
void testStdDistance() { // #10304
check("void foo(const std::vector<int>& IO, const int* pio) {\n"
"const auto Idx = std::distance(&IO.front(), pio);\n"
"printf(\"Idx = %td\", Idx);\n"
"}", /*inconclusive*/ false, /*portability*/ true);
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestIO)