Skip to content

gsl::not_null: C.89: Make a hash noexcept#1236

Merged
carsonRadtke merged 1 commit intomicrosoft:mainfrom
maflcko:2603-not-null-hash
Mar 23, 2026
Merged

gsl::not_null: C.89: Make a hash noexcept#1236
carsonRadtke merged 1 commit intomicrosoft:mainfrom
maflcko:2603-not-null-hash

Conversation

@maflcko
Copy link
Copy Markdown
Contributor

@maflcko maflcko commented Mar 23, 2026

Without this change, the guideline
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c89-make-a-hash-noexcept would be violated.

The test fails before the changes here:

tests/pointers_tests.cpp:102:23: error: static assertion failed due to requirement 'noexcept(std::hash<gsl::not_null<std::shared_ptr<int>>>{}(std::declval()))': gsl::not_null hash operator must be noexcept
  102 |         static_assert(noexcept(std::hash<Key>{}(std::declval<Key>())),
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests/pointers_tests.cpp:108:23: error: static assertion failed due to requirement 'noexcept(std::hash<gsl::strict_not_null<std::shared_ptr<int>>>{}(std::declval()))': gsl::strict_not_null hash operator must be noexcept
  108 |         static_assert(noexcept(std::hash<Key>{}(std::declval<Key>())),
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Without this change, the guideline
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c89-make-a-hash-noexcept
would be violated.

The test fails before the changes here:

```
tests/pointers_tests.cpp:102:23: error: static assertion failed due to requirement 'noexcept(std::hash<gsl::not_null<std::shared_ptr<int>>>{}(std::declval()))': gsl::not_null hash operator must be noexcept
  102 |         static_assert(noexcept(std::hash<Key>{}(std::declval<Key>())),
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests/pointers_tests.cpp:108:23: error: static assertion failed due to requirement 'noexcept(std::hash<gsl::strict_not_null<std::shared_ptr<int>>>{}(std::declval()))': gsl::strict_not_null hash operator must be noexcept
  108 |         static_assert(noexcept(std::hash<Key>{}(std::declval<Key>())),
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Copy link
Copy Markdown
Member

@carsonRadtke carsonRadtke left a comment

Choose a reason for hiding this comment

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

Cool! Thanks for finding this and getting a fix in.

@carsonRadtke carsonRadtke merged commit fcf3fe3 into microsoft:main Mar 23, 2026
87 checks passed
@maflcko maflcko deleted the 2603-not-null-hash branch March 24, 2026 06:51
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.

2 participants