Skip to content

Commit

Permalink
style: cleanup use of noexcept, explicit and = default (googlea…
Browse files Browse the repository at this point in the history
…pis/google-cloud-cpp-spanner#1209)

Our current rule-of-thumb is to only specify `noexcept` on hand-written
move constructors and assignments.  So, remove two current specifications
on defaulted move operators, and one on a normal constructor.  Fixes googleapis/google-cloud-cpp-spanner#228.

Reserve `explicit` for single-argument constructors.  Some ctor-arity
has changed over time, so some `explicit` annotations were missing or
outdated.

Also rewrite any `T() {}` constructor as `T() = default`.
  • Loading branch information
devbww authored Jan 22, 2020
1 parent a203e6b commit 8f64e9c
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 29 deletions.
6 changes: 3 additions & 3 deletions google/cloud/spanner/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::string BytesToBase64(Bytes b);
class Bytes {
public:
/// An empty sequence.
Bytes() {}
Bytes() = default;

/// Construction from a sequence of octets.
///@{
Expand Down Expand Up @@ -82,7 +82,7 @@ class Bytes {
friend std::string internal::BytesToBase64(Bytes b);

struct Encoder {
Encoder(std::string& rep) : rep_(rep), len_(0) {}
explicit Encoder(std::string& rep) : rep_(rep), len_(0) {}
void Flush();
void FlushAndPad();

Expand Down Expand Up @@ -135,7 +135,7 @@ class Bytes {
std::array<value_type, 1 + 3> buf_;
};

Decoder(std::string const& rep) : rep_(rep) {}
explicit Decoder(std::string const& rep) : rep_(rep) {}
iterator begin() { return iterator(rep_.begin(), rep_.end()); }
iterator end() { return iterator(rep_.end(), rep_.end()); }

Expand Down
3 changes: 1 addition & 2 deletions google/cloud/spanner/create_instance_request_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class CreateInstanceRequestBuilder {
* Constructor requires Instance and Cloud Spanner instance config name. It
* sets node_count = 1, and display_name = instance_id as the default values.
*/
explicit CreateInstanceRequestBuilder(Instance const& in,
std::string config) {
CreateInstanceRequestBuilder(Instance const& in, std::string config) {
request_.set_parent("projects/" + in.project_id());
request_.set_instance_id(in.instance_id());
request_.mutable_instance()->set_name(in.FullName());
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/spanner/internal/database_admin_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace internal {
*/
class DatabaseAdminLogging : public DatabaseAdminStub {
public:
explicit DatabaseAdminLogging(std::shared_ptr<DatabaseAdminStub> child,
TracingOptions tracing_options)
DatabaseAdminLogging(std::shared_ptr<DatabaseAdminStub> child,
TracingOptions tracing_options)
: child_(std::move(child)),
tracing_options_(std::move(tracing_options)) {}

Expand Down
4 changes: 2 additions & 2 deletions google/cloud/spanner/internal/instance_admin_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace gcsa = ::google::spanner::admin::instance::v1;
*/
class InstanceAdminLogging : public InstanceAdminStub {
public:
explicit InstanceAdminLogging(std::shared_ptr<InstanceAdminStub> child,
TracingOptions tracing_options)
InstanceAdminLogging(std::shared_ptr<InstanceAdminStub> child,
TracingOptions tracing_options)
: child_(std::move(child)),
tracing_options_(std::move(tracing_options)) {}

Expand Down
4 changes: 2 additions & 2 deletions google/cloud/spanner/internal/logging_result_set_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace internal {

class LoggingResultSetReader : public PartialResultSetReader {
public:
explicit LoggingResultSetReader(std::unique_ptr<PartialResultSetReader> impl,
TracingOptions tracing_options)
LoggingResultSetReader(std::unique_ptr<PartialResultSetReader> impl,
TracingOptions tracing_options)
: impl_(std::move(impl)), tracing_options_(std::move(tracing_options)) {}
~LoggingResultSetReader() override = default;

Expand Down
4 changes: 2 additions & 2 deletions google/cloud/spanner/internal/logging_spanner_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace internal {
*/
class LoggingSpannerStub : public SpannerStub {
public:
explicit LoggingSpannerStub(std::shared_ptr<SpannerStub> child,
TracingOptions tracing_options)
LoggingSpannerStub(std::shared_ptr<SpannerStub> child,
TracingOptions tracing_options)
: child_(std::move(child)),
tracing_options_(std::move(tracing_options)) {}
~LoggingSpannerStub() override = default;
Expand Down
9 changes: 4 additions & 5 deletions google/cloud/spanner/internal/range_from_pagination.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class PaginationIterator {
return std::rel_ops::operator!=(lhs, rhs);
}

explicit PaginationIterator(Range* owner, value_type value)
PaginationIterator(Range* owner, value_type value)
: owner_(owner), value_(std::move(value)) {}

Range* owner_;
Expand All @@ -108,10 +108,9 @@ class PaginationIterator {
template <typename T, typename Request, typename Response>
class PaginationRange {
public:
explicit PaginationRange(
Request request,
std::function<StatusOr<Response>(Request const& r)> loader,
std::function<std::vector<T>(Response r)> get_items)
PaginationRange(Request request,
std::function<StatusOr<Response>(Request const& r)> loader,
std::function<std::vector<T>(Response r)> get_items)
: request_(std::move(request)),
next_page_loader_(std::move(loader)),
get_items_(std::move(get_items)),
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/spanner/internal/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace internal {
*/
class Session {
public:
Session(std::string session_name, std::shared_ptr<SpannerStub> stub) noexcept
Session(std::string session_name, std::shared_ptr<SpannerStub> stub)
: session_name_(std::move(session_name)),
stub_(std::move(stub)),
is_bad_(false) {}
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/spanner/internal/transaction_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using VisitInvokeResult = ::google::cloud::internal::invoke_result_t<
*/
class TransactionImpl {
public:
TransactionImpl(google::spanner::v1::TransactionSelector selector)
explicit TransactionImpl(google::spanner::v1::TransactionSelector selector)
: TransactionImpl(/*session=*/{}, std::move(selector)) {}

TransactionImpl(TransactionImpl const& impl,
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/spanner/mutations.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class Mutation {
*/
Mutation() = default;

Mutation(Mutation&&) noexcept = default;
Mutation& operator=(Mutation&&) noexcept = default;
Mutation(Mutation&&) = default;
Mutation& operator=(Mutation&&) = default;
Mutation(Mutation const&) = default;
Mutation& operator=(Mutation const&) = default;

Expand Down
5 changes: 2 additions & 3 deletions google/cloud/spanner/query_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ class QueryPartition {
friend StatusOr<QueryPartition> DeserializeQueryPartition(
std::string const& serialized_query_partition);

explicit QueryPartition(std::string transaction_id, std::string session_id,
std::string partition_token,
SqlStatement sql_statement);
QueryPartition(std::string transaction_id, std::string session_id,
std::string partition_token, SqlStatement sql_statement);

// Accessor methods for use by friends.
std::string const& partition_token() const { return partition_token_; }
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/spanner/row.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ class Row {
* @note columns must not be nullptr
* @note columns.size() must equal values.size()
*/
explicit Row(std::vector<Value> values,
std::shared_ptr<const std::vector<std::string>> columns);
Row(std::vector<Value> values,
std::shared_ptr<const std::vector<std::string>> columns);

std::vector<Value> values_;
std::shared_ptr<const std::vector<std::string>> columns_;
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/spanner/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ class Value {
// this constructor matched their arguments best.
struct PrivateConstructor {};
template <typename T>
explicit Value(PrivateConstructor, T&& t)
Value(PrivateConstructor, T&& t)
: type_(MakeTypeProto(t)), value_(MakeValueProto(std::forward<T>(t))) {}

explicit Value(google::spanner::v1::Type t, google::protobuf::Value v)
Value(google::spanner::v1::Type t, google::protobuf::Value v)
: type_(std::move(t)), value_(std::move(v)) {}

friend Value internal::FromProto(google::spanner::v1::Type,
Expand Down

0 comments on commit 8f64e9c

Please sign in to comment.