Added cfg information about std::span (#4762)
* Added cfg information about std::span * Add tests for span handling * Add details about functions and tests fo std::span * Add tests in dangingLifetimeContainerView for span * Reduce c++ version from 20 to 2a * Add checking if span is supported in std lib cfg checks
This commit is contained in:
parent
5818520b4b
commit
7ae7ad60d8
39
cfg/std.cfg
39
cfg/std.cfg
|
@ -8486,6 +8486,37 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
|
|||
<not-uninit/>
|
||||
</arg>
|
||||
</function>
|
||||
<function name="std::span::first">
|
||||
<use-retval/>
|
||||
<returnValue type="std::span"/>
|
||||
<noreturn>false</noreturn>
|
||||
<arg nr="1" direction="in">
|
||||
<not-uninit/>
|
||||
<valid>0:</valid>
|
||||
</arg>
|
||||
</function>
|
||||
<function name="std::span::last">
|
||||
<use-retval/>
|
||||
<returnValue type="std::span"/>
|
||||
<noreturn>false</noreturn>
|
||||
<arg nr="1" direction="in">
|
||||
<not-uninit/>
|
||||
<valid>0:</valid>
|
||||
</arg>
|
||||
</function>
|
||||
<function name="std::span::subspan">
|
||||
<use-retval/>
|
||||
<returnValue type="std::span"/>
|
||||
<noreturn>false</noreturn>
|
||||
<arg nr="1" direction="in">
|
||||
<not-uninit/>
|
||||
<valid>0:</valid>
|
||||
</arg>
|
||||
<arg nr="2" direction="in">
|
||||
<not-uninit/>
|
||||
<valid>0:</valid>
|
||||
</arg>
|
||||
</function>
|
||||
<memory>
|
||||
<alloc init="false" buffer-size="malloc">malloc</alloc>
|
||||
<alloc init="true" buffer-size="calloc">calloc</alloc>
|
||||
|
@ -8700,6 +8731,13 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
|
|||
<container id="stdStringView" startPattern="std :: string_view|wstring_view|u16string_view|u32string_view" endPattern="" inherits="stdAllStringView"/>
|
||||
<container id="stdExperimentalStringView" startPattern="std :: experimental :: string_view|wstring_view|u16string_view|u32string_view" endPattern="" inherits="stdAllStringView"/>
|
||||
<container id="stdExperimentalBasicStringView" startPattern="std :: experimental :: basic_string_view <" inherits="stdBasicStringView" />
|
||||
<container id="stdSpan" startPattern="std :: span" endPattern="" inherits="stdContainer" view="true">
|
||||
<access indexOperator="array-like">
|
||||
<function name="front" yields="item"/>
|
||||
<function name="back" yields="item"/>
|
||||
<function name="data" yields="buffer"/>
|
||||
</access>
|
||||
</container>
|
||||
<smart-pointer class-name="std::auto_ptr">
|
||||
<unique/>
|
||||
</smart-pointer>
|
||||
|
@ -8747,6 +8785,7 @@ initializer list (7) string& replace (const_iterator i1, const_iterator i2, init
|
|||
<check>std::ios_base::failure</check>
|
||||
<check>std::filesystem::filesystem_error</check>
|
||||
<check>std::bad_variant_access</check>
|
||||
<check>std::span</check>
|
||||
</unusedvar>
|
||||
<operatorEqVarError>
|
||||
<suppress>std::mutex</suppress>
|
||||
|
|
|
@ -27,7 +27,7 @@ CPPCHECK_OPT='--check-library --platform=unix64 --enable=style --error-exitcode=
|
|||
|
||||
# Compiler settings
|
||||
CXX=g++
|
||||
CXX_OPT='-fsyntax-only -std=c++17 -Wno-format -Wno-format-security -Wno-deprecated-declarations'
|
||||
CXX_OPT='-fsyntax-only -std=c++2a -Wno-format -Wno-format-security -Wno-deprecated-declarations'
|
||||
CC=gcc
|
||||
CC_OPT='-Wno-format -Wno-stringop-overread -Wno-nonnull -Wno-implicit-function-declaration -Wno-deprecated-declarations -Wno-format-security -Wno-nonnull -fsyntax-only'
|
||||
|
||||
|
|
|
@ -39,6 +39,10 @@
|
|||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <version>
|
||||
#ifdef __cpp_lib_span
|
||||
#include <span>
|
||||
#endif
|
||||
|
||||
int zerodiv_ldexp()
|
||||
{
|
||||
|
@ -4562,4 +4566,43 @@ void string_view_unused(std::string_view v)
|
|||
{
|
||||
// cppcheck-suppress ignoredReturnValue
|
||||
v.substr(1, 3);
|
||||
}
|
||||
|
||||
void stdspan()
|
||||
{
|
||||
#ifndef __cpp_lib_span
|
||||
#warning "This compiler does not support std::span"
|
||||
#else
|
||||
std::vector<int> vec{1,2,3,4};
|
||||
std::span spn{vec};
|
||||
// cppcheck-suppress unreadVariable
|
||||
std::span spn2 = spn;
|
||||
|
||||
spn.begin();
|
||||
spn.end();
|
||||
spn.rbegin();
|
||||
spn.end();
|
||||
|
||||
spn.front();
|
||||
spn.back();
|
||||
//cppcheck-suppress constStatement
|
||||
spn[0];
|
||||
spn.data();
|
||||
spn.size();
|
||||
spn.size_bytes();
|
||||
spn.empty();
|
||||
//cppcheck-suppress ignoredReturnValue
|
||||
spn.first(2);
|
||||
//cppcheck-suppress ignoredReturnValue
|
||||
spn.last(2);
|
||||
//cppcheck-suppress ignoredReturnValue
|
||||
spn.subspan(1, 2);
|
||||
spn.subspan<1>();
|
||||
|
||||
static constexpr std::array<int, 2> arr{1, 2};
|
||||
constexpr std::span spn3{arr};
|
||||
spn3.first<1>();
|
||||
spn3.last<1>();
|
||||
spn3.subspan<1, 1>();
|
||||
#endif
|
||||
}
|
|
@ -2799,6 +2799,91 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2] -> [test.cpp:3]: (error) Using object that is a temporary.\n",
|
||||
errout.str());
|
||||
|
||||
check("std::span<int> f() {\n"
|
||||
" std::vector<int> v{};\n"
|
||||
" return v;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
|
||||
errout.str());
|
||||
|
||||
check("std::span<int> f() {\n"
|
||||
" std::vector<int> v;\n"
|
||||
" std::span sp = v;\n"
|
||||
" return sp;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:4]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
|
||||
errout.str());
|
||||
|
||||
check("std::span<int> f() {\n"
|
||||
" std::vector<int> v;\n"
|
||||
" return std::span{v};\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:3] -> [test.cpp:2] -> [test.cpp:3]: (error) Returning object that points to local variable 'v' that will be invalid when returning.\n",
|
||||
errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" std::span<int> s;\n"
|
||||
" {\n"
|
||||
" std::vector<int> v(1);"
|
||||
" s = v;\n"
|
||||
" }\n"
|
||||
"return s.back()\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
|
||||
errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" std::span<int> s;\n"
|
||||
" {\n"
|
||||
" std::vector<int> v(1);"
|
||||
" s = v;\n"
|
||||
" }\n"
|
||||
"return s.back()\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
|
||||
errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" std::span<int> s;\n"
|
||||
" {\n"
|
||||
" std::vector<int> v(1);"
|
||||
" s = v;\n"
|
||||
" }\n"
|
||||
"return s.front()\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
|
||||
errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" std::span<int> s;\n"
|
||||
" {\n"
|
||||
" std::vector<int> v(1);"
|
||||
" s = v;\n"
|
||||
" }\n"
|
||||
"return s.last(1)\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
|
||||
errout.str());
|
||||
|
||||
check("int f() {\n"
|
||||
" std::span<int> s;\n"
|
||||
" {\n"
|
||||
" std::vector<int> v(1);"
|
||||
" s = v;\n"
|
||||
" }\n"
|
||||
"return s.first(1)\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS(
|
||||
"[test.cpp:4] -> [test.cpp:4] -> [test.cpp:6]: (error) Using object that points to local variable 'v' that is out of scope.\n",
|
||||
errout.str());
|
||||
}
|
||||
|
||||
void danglingLifetimeUniquePtr()
|
||||
|
|
Loading…
Reference in New Issue