================
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -verify %s
+
+namespace std {
+ typedef __SIZE_TYPE__ size_t;
+
+ template <typename CharT>
+ class basic_string_view {
+ public:
+ basic_string_view(const CharT *s, size_t count);
+ basic_string_view(const CharT *s);
+ template <typename It>
+ basic_string_view(It begin, It end);
+ };
+
+ using string_view = basic_string_view<char>;
+}
+
+void test_string_view_scenarios(const char *ptr, std::size_t n) {
+ // --- UNSAFE CASES ---
+ std::string_view sv1(ptr, n);
+ // expected-warning@-1 {{the two-parameter std::string_view construction is
unsafe as it can introduce mismatch between buffer size and the bound
information}}
+
+ // --- SAFE CASES (Should NOT warn for string_view construction) ---
+ std::string_view sv2("hello", 5); // Safe: String literal match
----------------
rohanjr wrote:
Add a test for size argument < string literal size (which you allow as one of
the safe patterns)?
https://github.com/llvm/llvm-project/pull/180471
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits