Skip to content

Add ABSL_ATTRIBUTE_UNSAFE_BUFFER_USAGE_IN_CONTAINER and apply it to absl::Span. - #2420

Draft
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1005970571
Draft

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_1005970571

Conversation

@copybara-service

Copy link
Copy Markdown

Add ABSL_ATTRIBUTE_UNSAFE_BUFFER_USAGE_IN_CONTAINER and apply it to absl::Span.

Clang's -Wunsafe-buffer-usage-in-container flags two-parameter std::span constructions whose arguments are not provably safe. The new macro wraps [[clang::unsafe_buffer_usage_in_container]], which opts other container and view types into the same check, and expands to nothing on compilers that do not support the attribute.

Apply it to the (pointer, length) constructor of absl::Span and the (pointer, length) and (begin, end) overloads of absl::MakeSpan() and absl::MakeConstSpan(), so that calls such as absl::Span<int>(p, n) are diagnosed while absl::Span<int>(v.data(), v.size()) is not.

…bsl::Span.

Clang's `-Wunsafe-buffer-usage-in-container` flags two-parameter `std::span` constructions whose arguments are not provably safe. The new macro wraps `[[clang::unsafe_buffer_usage_in_container]]`, which opts other container and view types into the same check, and expands to nothing on compilers that do not support the attribute.

Apply it to the (pointer, length) constructor of `absl::Span` and the (pointer, length) and (begin, end) overloads of `absl::MakeSpan()` and `absl::MakeConstSpan()`, so that calls such as `absl::Span<int>(p, n)` are diagnosed while `absl::Span<int>(v.data(), v.size())` is not.

PiperOrigin-RevId: 1005970571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants