From 67c31d794e3eea00af7f4a38965cf8a38a6f1f72 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sat, 28 May 2016 14:09:46 -0400 Subject: [PATCH] Protect undocumented constructors --- tz.cpp | 13 +++++++++---- tz.h | 9 +++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tz.cpp b/tz.cpp index 1efadbe..1ed7132 100644 --- a/tz.cpp +++ b/tz.cpp @@ -126,6 +126,11 @@ CONSTDATA auto max_day = date::dec/31; // | End Configuration | // +-------------------+ +namespace detail +{ +class undocumented {explicit undocumented() = default;}; +} + #ifndef _MSC_VER static_assert(min_year <= max_year, "Configuration error"); #endif @@ -1262,7 +1267,7 @@ time_zone::zonelet::zonelet(const zonelet& i) #endif } -time_zone::time_zone(const std::string& s) +time_zone::time_zone(const std::string& s, detail::undocumented) #if LAZY_INIT : adjusted_(new std::once_flag{}) #endif @@ -1923,7 +1928,7 @@ operator<<(std::ostream& os, const Link& x) // Leap -Leap::Leap(const std::string& s) +Leap::Leap(const std::string& s, detail::undocumented) { using namespace date; std::istringstream in(s); @@ -2146,12 +2151,12 @@ init_tzdb() } else if (word == "Leap") { - db.leaps.push_back(Leap(line)); + db.leaps.push_back(Leap(line, detail::undocumented{})); continue_zone = false; } else if (word == "Zone") { - db.zones.push_back(time_zone(line)); + db.zones.push_back(time_zone(line, detail::undocumented{})); continue_zone = true; } else if (line[0] == '\t' && continue_zone) diff --git a/tz.h b/tz.h index 8bbe912..ee9dde3 100644 --- a/tz.h +++ b/tz.h @@ -99,6 +99,11 @@ namespace date enum class choose {earliest, latest}; +namespace detail +{ + class undocumented; +} + class nonexistent_local_time : public std::runtime_error { @@ -321,7 +326,7 @@ public: time_zone& operator=(time_zone&& src); #endif // defined(_MSC_VER) && (_MSC_VER < 1900) - explicit time_zone(const std::string& s); + explicit time_zone(const std::string& s, detail::undocumented); const std::string& name() const; @@ -517,7 +522,7 @@ private: sys_seconds date_; public: - explicit Leap(const std::string& s); + explicit Leap(const std::string& s, detail::undocumented); sys_seconds date() const {return date_;}