aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-11-21 11:52:34 +0000
committerJonathan Wakely <jwakely@redhat.com>2022-11-21 17:46:42 +0000
commited77dcb9be76e592b62449c75a5e751485514afd (patch)
treef3567c9e885b2c357173c2f3fc481eae0d70d5e2
parent94f7baf2194e2d20108c9d34d2766e6b14e25cef (diff)
downloadgcc-ed77dcb9be76e592b62449c75a5e751485514afd.zip
gcc-ed77dcb9be76e592b62449c75a5e751485514afd.tar.gz
gcc-ed77dcb9be76e592b62449c75a5e751485514afd.tar.bz2
libstdc++: Check static assertions earlier in chrono::duration
This ensures that we fail a static assertion before giving any other errors. Instantiating chrono::duration<int, chrono::seconds> will now print this before the other errors caused by it: error: static assertion failed: period must be a specialization of ratio libstdc++-v3/ChangeLog: * include/bits/chrono.h (duration): Check preconditions on template arguments before using them.
-rw-r--r--libstdc++-v3/include/bits/chrono.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/libstdc++-v3/include/bits/chrono.h b/libstdc++-v3/include/bits/chrono.h
index 05987ca..cabf612 100644
--- a/libstdc++-v3/include/bits/chrono.h
+++ b/libstdc++-v3/include/bits/chrono.h
@@ -433,6 +433,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Rep, typename _Period>
struct duration
{
+ static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration");
+ static_assert(__is_ratio<_Period>::value,
+ "period must be a specialization of ratio");
+ static_assert(_Period::num > 0, "period must be positive");
+
private:
template<typename _Rep2>
using __is_float = treat_as_floating_point<_Rep2>;
@@ -478,11 +483,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using rep = _Rep;
using period = typename _Period::type;
- static_assert(!__is_duration<_Rep>::value, "rep cannot be a duration");
- static_assert(__is_ratio<_Period>::value,
- "period must be a specialization of ratio");
- static_assert(_Period::num > 0, "period must be positive");
-
// 20.11.5.1 construction / copy / destroy
constexpr duration() = default;