1 // RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \
6 template< class InputIt
, class OutputIt
>
7 OutputIt
copy( InputIt first
, InputIt last
,
15 unsigned size_bytes();
17 iterator
begin() const noexcept
;
18 iterator
end() const noexcept
;
26 unsigned size_bytes();
29 typedef basic_string
<char> string
;
30 typedef basic_string
<wchar_t> wstring
;
32 // C function under std:
35 int snprintf( char* buffer
, unsigned buf_size
, const char* format
, ... );
39 void f(char * p
, char * q
, std::span
<char> s
) {
40 std::memcpy(); // expected-warning{{function 'memcpy' is unsafe}}
41 std::strcpy(); // expected-warning{{function 'strcpy' is unsafe}}
42 std::__1::memcpy(); // expected-warning{{function 'memcpy' is unsafe}}
43 std::__1::strcpy(); // expected-warning{{function 'strcpy' is unsafe}}
46 std::snprintf(s
.data(), 10, "%s%d", "hello", *p
); // expected-warning{{function 'snprintf' is unsafe}} expected-note{{buffer pointer and size may not match}}
47 std::__1::snprintf(s
.data(), 10, "%s%d", "hello", *p
); // expected-warning{{function 'snprintf' is unsafe}} expected-note{{buffer pointer and size may not match}}
48 std::snprintf(s
.data(), s
.size_bytes(), "%s%d", "hello", *p
); // no warn
49 std::__1::snprintf(s
.data(), s
.size_bytes(), "%s%d", "hello", *p
); // no warn
52 void v(std::string s1
) {
53 std::snprintf(s1
.data(), s1
.size_bytes(), "%s%d", s1
.c_str(), 0); // no warn
54 std::__1::snprintf(s1
.data(), s1
.size_bytes(), "%s%d", s1
.c_str(), 0); // no warn
57 void g(char *begin
, char *end
, char *p
, std::span
<char> s
) {
58 std::copy(begin
, end
, p
); // no warn
59 std::copy(s
.begin(), s
.end(), s
.begin()); // no warn