Skip to content

Document differences between hardened std::span and gsl::span - #1206

Merged
Carson Radtke (carsonRadtke) merged 5 commits into
mainfrom
copilot/fix-1199
May 22, 2025
Merged

Carson Radtke (carsonRadtke) merged 5 commits into
mainfrom
copilot/fix-1199

Conversation

Copilot AI commented May 21, 2025

Copy link
Copy Markdown
Contributor

This PR adds documentation explaining the differences between gsl::span and the upcoming hardened std::span in C++26, as specified in P3471: Standard library hardening.

Changes

  • Created a new FAQ.md file in the docs directory with detailed explanations of:

    • Current differences between gsl::span and std::span
    • Expected differences between gsl::span and hardened std::span in C++26
    • Guidance on when to use each implementation
  • Updated README.md with a reference to the FAQ when describing gsl::span

  • Enhanced the span documentation in headers.md with more detailed information about the differences and a link to the FAQ

With these changes, users will be able to make informed decisions about which span implementation to use based on their specific needs, especially as C++26 approaches with its hardened standard library components.

Fixes #1199.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.fwupd.org
    • Triggering command: /usr/bin/fwupdmgr refresh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: carsonRadtke <10507970+carsonRadtke@users.noreply.github.com>
Copilot AI changed the title [WIP] Document the differences between hardened std::span and gsl::span Document differences between hardened std::span and gsl::span May 21, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address my comment. I don't think you need a whole word-wall FAQ - just enough info for a user to make an informed decision.

Comment thread docs/headers.md Outdated

With the adoption of [P3471: Standard library hardening](https://isocpp.org/files/papers/P3471R4.html) in C++26,
the gap between `std::span` and `gsl::span` is narrowing, but differences remain. For detailed information about the
differences and guidance on which one to use, see the [FAQ](FAQ.md#what-are-the-differences-between-gslspan-and-hardened-stdspan-in-c26).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not introduce a whole FAQ file. I think here it is fine to just say:

--

  • C++14 + C++17 -> Use gsl::span because it is your only option.
  • C++20 + C++23 -> Use gsl::span because accesses are bounds checked.
  • C++26* -> Use gsl::span because iterators are hardened too.

* C++26 or a backported standard library implementation.

Something also to note is that the behavior-on-error is not configurable for GSL (std::terminate()), but it may be configurable for library implementations.

--

This is the gist, but please make the style more similar to the rest of the document and add links as necessary. Also, a chart may provide a helpful visual.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the changes as requested in 8f9d1d6. I've added a concise table-like format directly in headers.md that explains when to use each span version based on C++ standard version. I also added the note about behavior-on-error configurability, removed the FAQ file entirely, and kept the style consistent with the rest of the document.

Co-authored-by: carsonRadtke <10507970+carsonRadtke@users.noreply.github.com>

Copilot AI commented May 21, 2025

Copy link
Copy Markdown
Contributor Author

Address my comment. I don't think you need a whole word-wall FAQ - just enough info for a user to make an informed decision.

I've simplified the documentation as requested. Instead of using a separate FAQ file, I've added a concise explanation directly in headers.md that follows the C++ version guidelines you suggested. The changes in 8f9d1d6 include:

  1. Clear recommendations for each C++ version
  2. Note about configurability differences
  3. Removed the FAQ file
  4. Updated the README.md to remove the FAQ reference

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.fwupd.org
    • Triggering command: /usr/bin/fwupdmgr refresh (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you injected my previous comment into the document. That was good for an outline, but I'd like you to fill in some more information.

Comment thread docs/headers.md
- Any violations of the bounds check results in termination of the program
- `gsl::span`'s iterators also perform bounds checking, unlike `std::span`'s iterators

#### Which version of span should I use?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this section a table? I'd like to have a row for each category and columns for std::span, std::span w/ hardening, and gsl::span. The each cell in the table can offer a little more context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've converted this section to a table in commit d3f39fa. The table now has rows for C++ standard requirements, element access, iterator safety, error behavior, and performance, with columns for std::span, hardened std::span, and gsl::span.

Comment thread docs/headers.md Outdated
##### Use `std::span` if

- your project is C++20 and you need the performance offered by `std::span`.
Note that the behavior on bounds check violations is not configurable for GSL (`std::terminate()`),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a little more info here and make the style match the rest of the document?

Ideally there would be links to the hardening documentation for libc++, libstdc++, and STL. Also a link to the bounds-check violation handler in GSL may be useful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added more detailed information in commit d3f39fa, including links to the GSL bounds-check handler implementation and links to the major C++ standard library implementations (MSVC STL, libc++, and libstdc++) documentation. The style now matches the rest of the document with proper formatting and structure.

Co-authored-by: carsonRadtke <10507970+carsonRadtke@users.noreply.github.com>

Copilot AI commented May 21, 2025

Copy link
Copy Markdown
Contributor Author

Looks like you injected my previous comment into the document. That was good for an outline, but I'd like you to fill in some more information.

I've enhanced the documentation with more detailed information about span implementations in commit d3f39fa. I replaced the outline with a comprehensive comparison table along with specific recommendations for different C++ standard versions and links to relevant documentation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Can you just fix this links as suggested?

Comment thread docs/headers.md Outdated
**Implementation notes for hardened `std::span` in C++26:**
- For MSVC: See [Microsoft STL documentation](https://learn.microsoft.com/cpp/standard-library/library-features-cpp) for hardening options
- For Clang/LLVM: See [libc++ implementation notes](https://libcxx.llvm.org/)
- For GCC: See [libstdc++ implementation notes](https://gcc.gnu.org/onlinedocs/libstdc++/)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link doesn't mention anything about library hardening, can you delete it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the GCC libstdc++ link as it doesn't contain information about library hardening in commit 460ced0.

Comment thread docs/headers.md Outdated
- Use hardened `std::span` if you want standard library compliance and acceptable safety.

**Implementation notes for hardened `std::span` in C++26:**
- For MSVC: See [Microsoft STL documentation](https://learn.microsoft.com/cpp/standard-library/library-features-cpp) for hardening options

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link is broken. Use this instead: https://github.com/microsoft/STL/wiki/STL-Hardening

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the MSVC STL link to point to the STL Hardening wiki page in commit 460ced0.

Comment thread docs/headers.md Outdated

**Implementation notes for hardened `std::span` in C++26:**
- For MSVC: See [Microsoft STL documentation](https://learn.microsoft.com/cpp/standard-library/library-features-cpp) for hardening options
- For Clang/LLVM: See [libc++ implementation notes](https://libcxx.llvm.org/)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the libc++ link to point to the Hardening documentation page in commit 460ced0.

Co-authored-by: carsonRadtke <10507970+carsonRadtke@users.noreply.github.com>

Copilot AI commented May 22, 2025

Copy link
Copy Markdown
Contributor Author

Cool. Can you just fix this links as suggested?

I've fixed all the links as requested in commit 460ced0. The changes include:

  1. Updated the MSVC STL link to point to the STL Hardening wiki page
  2. Updated the libc++ link to point to their Hardening documentation
  3. Removed the GCC libstdc++ link as it doesn't contain specific hardening information

@carsonRadtke
Carson Radtke (carsonRadtke) marked this pull request as ready for review May 22, 2025 17:34
@carsonRadtke
Carson Radtke (carsonRadtke) deleted the copilot/fix-1199 branch May 22, 2025 17:34
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.

Document the differences between hardened std::span and gsl::span

2 participants