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 more zview constructors noexcept. #625

Merged
merged 3 commits into from
Jan 14, 2023
Merged

Make more zview constructors noexcept. #625

merged 3 commits into from
Jan 14, 2023

Conversation

jtv
Copy link
Owner

@jtv jtv commented Jan 14, 2023

This is a silly problem to have. In a way it's good. Sometimes gcc
warns (and in my development builds, warnings are errors!) that some
zview constructors throw no errors, and would I perhaps like to slap
a noexcept on them?

A fine idea, were it not for the facts that (1) pqxx::zview extends
std::string_view, and (2) the corresponding string_view constructor
does not have the noexcept. So... can I make that promise myself?

Turns out I can. Looking at gcc's string_view implementation I see
that it does declare those constructors as noexcept. All I had to do
was declare my constructors as "noexcept provided that string_view
is okay with it.")

This is a silly problem to have.  In a way it's good.  Sometimes gcc
warns (and in my development builds, warnings are errors!) that some
`zview` constructors throw no errors, and would I perhaps like to slap
a `noexcept` on them?

A _fine_ idea, were it not for the facts that (1) `pqxx::zview` extends
`std::string_view`, and (2) the corresponding `string_view` constructor
does not have the `noexcept`.  So... can I make that promise myself?

Turns out I can.  Looking at gcc's `string_view` implementation I see
that it does declare those constructors as `noexcept`.  All I had to do
was declare my constructors as "`noexcept` provided that `string_view`
is okay with it.")
@jtv jtv changed the title Make more zview constructots noexcept. Make more zview constructors noexcept. Jan 14, 2023
@@ -73,7 +75,8 @@
* do it many times, it's probably better to create the `zview` once and
* re-use it.
*/
constexpr zview(char const str[]) : std::string_view{str} {}
constexpr zview(char const str[]) noexcept(noexcept(std::string_view{str})) :

Check notice

Code scanning / CodeQL

No raw arrays in interfaces

Raw arrays should not be used in interfaces. A container class should be used instead.
std::string_view{text, static_cast<std::size_t>(len)}
{}

/// Convenience overload: construct using pointer and signed length.
constexpr zview(char text[], std::ptrdiff_t len) :
constexpr zview(char text[], std::ptrdiff_t len)

Check notice

Code scanning / CodeQL

No raw arrays in interfaces

Raw arrays should not be used in interfaces. A container class should be used instead.
@@ -40,12 +40,14 @@
constexpr zview() noexcept = default;

/// Convenience overload: construct using pointer and signed length.
constexpr zview(char const text[], std::ptrdiff_t len) :
constexpr zview(char const text[], std::ptrdiff_t len)

Check notice

Code scanning / CodeQL

No raw arrays in interfaces

Raw arrays should not be used in interfaces. A container class should be used instead.
@jtv jtv merged commit 142b920 into master Jan 14, 2023
@jtv jtv deleted the zview-noexcept branch January 14, 2023 23:21
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.

1 participant