================ @@ -232,3 +268,27 @@ struct HoldsStdSpanAndNotInitializedInCtor { : Ptr(P), Size(S) {} }; + +namespace test_begin_end { + struct Object { + int * begin(); + int * end(); + }; + void safe_cases(std::span<int> Sp, std::array<int, 10> Arr, std::string Str, std::initializer_list<Object> Il) { + std::span<int>{Sp.begin(), Sp.end()}; + std::span<int>{Arr.begin(), Arr.end()}; + std::span<char>{Str.begin(), Str.end()}; + std::span<Object>{Il.begin(), Il.end()}; + } + + void unsafe_cases(std::span<int> Sp, std::array<int, 10> Arr, std::string Str, std::initializer_list<Object> Il, + Object Obj) { + std::span<int>{Obj.begin(), Obj.end()}; // expected-warning {{the two-parameter std::span construction is unsafe as it can introduce mismatch between buffer size and the bound information}} + std::span<int>{Sp.end(), Sp.begin()}; // expected-warning {{the two-parameter std::span construction is unsafe as it can introduce mismatch between buffer size and the bound information}} ---------------- ziqingluo-90 wrote:
My understanding is that it warns about the mismatch between **the bound information of the constructed span** and the actual buffer size. So I think the message is accurate regardless of how the span is constructed. https://github.com/llvm/llvm-project/pull/145311 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits