Protect undocumented constructors

This commit is contained in:
Howard Hinnant
2016-05-28 14:09:46 -04:00
parent c0de8dc843
commit 67c31d794e
2 changed files with 16 additions and 6 deletions

13
tz.cpp
View File

@@ -126,6 +126,11 @@ CONSTDATA auto max_day = date::dec/31;
// | End Configuration | // | End Configuration |
// +-------------------+ // +-------------------+
namespace detail
{
class undocumented {explicit undocumented() = default;};
}
#ifndef _MSC_VER #ifndef _MSC_VER
static_assert(min_year <= max_year, "Configuration error"); static_assert(min_year <= max_year, "Configuration error");
#endif #endif
@@ -1262,7 +1267,7 @@ time_zone::zonelet::zonelet(const zonelet& i)
#endif #endif
} }
time_zone::time_zone(const std::string& s) time_zone::time_zone(const std::string& s, detail::undocumented)
#if LAZY_INIT #if LAZY_INIT
: adjusted_(new std::once_flag{}) : adjusted_(new std::once_flag{})
#endif #endif
@@ -1923,7 +1928,7 @@ operator<<(std::ostream& os, const Link& x)
// Leap // Leap
Leap::Leap(const std::string& s) Leap::Leap(const std::string& s, detail::undocumented)
{ {
using namespace date; using namespace date;
std::istringstream in(s); std::istringstream in(s);
@@ -2146,12 +2151,12 @@ init_tzdb()
} }
else if (word == "Leap") else if (word == "Leap")
{ {
db.leaps.push_back(Leap(line)); db.leaps.push_back(Leap(line, detail::undocumented{}));
continue_zone = false; continue_zone = false;
} }
else if (word == "Zone") else if (word == "Zone")
{ {
db.zones.push_back(time_zone(line)); db.zones.push_back(time_zone(line, detail::undocumented{}));
continue_zone = true; continue_zone = true;
} }
else if (line[0] == '\t' && continue_zone) else if (line[0] == '\t' && continue_zone)

9
tz.h
View File

@@ -99,6 +99,11 @@ namespace date
enum class choose {earliest, latest}; enum class choose {earliest, latest};
namespace detail
{
class undocumented;
}
class nonexistent_local_time class nonexistent_local_time
: public std::runtime_error : public std::runtime_error
{ {
@@ -321,7 +326,7 @@ public:
time_zone& operator=(time_zone&& src); time_zone& operator=(time_zone&& src);
#endif // defined(_MSC_VER) && (_MSC_VER < 1900) #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; const std::string& name() const;
@@ -517,7 +522,7 @@ private:
sys_seconds date_; sys_seconds date_;
public: public:
explicit Leap(const std::string& s); explicit Leap(const std::string& s, detail::undocumented);
sys_seconds date() const {return date_;} sys_seconds date() const {return date_;}