Skip to content

Commit

Permalink
Merge pull request ceph#38781 from tchaikov/wip-googletest-gcc11
Browse files Browse the repository at this point in the history
googletest: pick up change to silence error=maybe-uninitialized warning

Reviewed-by: Neha Ojha <[email protected]>
Reviewed-by: Adam C. Emerson <[email protected]>
Reviewed-by: Jason Dillaman <[email protected]>
  • Loading branch information
tchaikov authored Jan 12, 2021
2 parents e536313 + abbdf33 commit ae8d603
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
46 changes: 34 additions & 12 deletions src/common/ceph_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

// For ceph_timespec
#include "ceph_time.h"

#include <fmt/chrono.h>
#include <fmt/ostream.h>

#include "log/LogClock.h"
#include "config.h"
#include "strtol.h"
Expand Down Expand Up @@ -102,18 +106,6 @@ std::ostream& operator<<(std::ostream& m,
<< 's';
}

std::ostream& operator<<(std::ostream& m, const timespan& t) {
static_assert(std::is_unsigned_v<timespan::rep>);
m << std::chrono::duration_cast<std::chrono::seconds>(t).count();
if (auto ns = (t % 1s).count(); ns > 0) {
char oldfill = m.fill();
m.fill('0');
m << '.' << std::setw(9) << ns;
m.fill(oldfill);
}
return m << 's';
}

template<typename Clock,
typename std::enable_if<!Clock::is_steady>::type*>
std::ostream& operator<<(std::ostream& m,
Expand Down Expand Up @@ -328,3 +320,33 @@ std::chrono::seconds parse_timespan(const std::string& s)
}

}

namespace std {
template<typename Rep, typename Period>
ostream& operator<<(ostream& m, const chrono::duration<Rep, Period>& t) {
if constexpr (chrono::treat_as_floating_point_v<Rep>) {
using seconds_t = chrono::duration<float>;
::fmt::print(m, "{:.9}", chrono::duration_cast<seconds_t>(t));
} else {
::fmt::print(m, "{}", t);
}
return m;
}

template ostream&
operator<< <::ceph::timespan::rep,
::ceph::timespan::period> (ostream&, const ::ceph::timespan&);

template ostream&
operator<< <::ceph::signedspan::rep,
::ceph::signedspan::period> (ostream&, const ::ceph::signedspan&);

template ostream&
operator<< <chrono::seconds::rep,
chrono::seconds::period> (ostream&, const chrono::seconds&);

template ostream&
operator<< <chrono::milliseconds::rep,
chrono::milliseconds::period> (ostream&, const chrono::milliseconds&);

} // namespace std
6 changes: 5 additions & 1 deletion src/common/ceph_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ inline std::optional<timespan> maybe_timespan(const double d) {
return d ? std::make_optional(make_timespan(d)) : std::nullopt;
}

std::ostream& operator<<(std::ostream& m, const timespan& t);
template<typename Clock,
typename std::enable_if<!Clock::is_steady>::type* = nullptr>
std::ostream& operator<<(std::ostream& m,
Expand Down Expand Up @@ -519,4 +518,9 @@ static Rep to_microseconds(T t) {

} // namespace ceph

namespace std {
template<typename Rep, typename Period>
ostream& operator<<(ostream& m, const chrono::duration<Rep, Period>& t);
}

#endif // COMMON_CEPH_TIME_H
2 changes: 1 addition & 1 deletion src/googletest
Submodule googletest updated 113 files
1 change: 0 additions & 1 deletion src/include/CompatSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ struct CompatSet {
};
WRITE_CLASS_ENCODER(CompatSet)

using ceph::operator <<;
inline std::ostream& operator<<(std::ostream& out, const CompatSet::FeatureSet& fs)
{
return out << fs.names;
Expand Down
6 changes: 4 additions & 2 deletions src/test/test_rbd_replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
#include "rbd_replay/rbd_loc.hpp"


using namespace rbd_replay;

namespace rbd_replay {
std::ostream& operator<<(std::ostream& o, const rbd_loc& name) {
return o << "('" << name.pool << "', '" << name.image << "', '" << name.snap << "')";
}
}

using namespace rbd_replay;

static void add_mapping(ImageNameMap *map, std::string mapping_string) {
ImageNameMap::Mapping mapping;
Expand Down

0 comments on commit ae8d603

Please sign in to comment.