Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make not_null<foo*> trivially copyable. #3304

Merged
merged 4 commits into from
Jan 26, 2022

Conversation

rnlahaye
Copy link
Contributor

This fixes an annoying -Wrange-loop-construct clang warning.

Done by creating a wrapper struct that uses the default move assignment operator for trivially move assignable pointers and the custom swap-based move assignment operator for others.

This fixes an annoying -Wrange-loop-construct clang warning.
@pleroy
Copy link
Member

pleroy commented Jan 23, 2022

Lint errors:

  | not_null.hpp:104 | runtime/explicit | High | 1
  | not_null.hpp:117 | runtime/explicit | High | 1
  | not_null.hpp:123 | build/include_what_you_use | Normal | 1
  | not_null.hpp:218 | whitespace/line_length | Low | 1
  | not_null.hpp:97 | whitespace/operators | Normal | 1

@@ -262,5 +268,25 @@ TEST_F(NotNullTest, RValue) {
EXPECT_EQ(5, *owner_const_int);
}

TEST_F(NotNullTest, TypeTraits) {
// not_null<foo*> is trivially copyable.
EXPECT_TRUE(std::is_trivially_copyable_v<not_null<int*>>);
Copy link
Member

@eggrobin eggrobin Jan 23, 2022

Choose a reason for hiding this comment

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

Change all of those to static_assert (cf. https://github.com/mockingbirdnest/Principia/blob/master/numerics/next_test.cpp which tests constexpr code).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@pleroy
Copy link
Member

pleroy commented Jan 24, 2022

The linter is still unhappy (and somewhat dumb):

not_null.hpp:124 build/include_what_you_use Normal 1
Add #include <algorithm> for swap

@eggrobin eggrobin added the LGTM label Jan 26, 2022
@eggrobin eggrobin merged commit 84fad5f into mockingbirdnest:master Jan 26, 2022
@rnlahaye rnlahaye deleted the not_null branch January 27, 2022 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants