[libc++][chrono] Implement LWG 4481: Disallow chrono::duration<const T, P> (#207558)
This commit is contained in:
parent
063ac503e4
commit
459cadfaf1
4 changed files with 31 additions and 1 deletions
|
|
@ -301,7 +301,7 @@
|
|||
"`LWG4477 <https://wg21.link/LWG4477>`__","Placement ``operator delete`` should be constexpr","2026-03 (Croydon)","|Complete|","23","`#189843 <https://github.com/llvm/llvm-project/issues/189843>`__",""
|
||||
"`LWG4478 <https://wg21.link/LWG4478>`__","``meta::has_identifier`` is not specified for annotations","2026-03 (Croydon)","","","`#189844 <https://github.com/llvm/llvm-project/issues/189844>`__",""
|
||||
"`LWG4480 <https://wg21.link/LWG4480>`__","``<stdatomic.h>`` should provide ``ATOMIC_CHAR8_T_LOCK_FREE``","2026-03 (Croydon)","","","`#189845 <https://github.com/llvm/llvm-project/issues/189845>`__",""
|
||||
"`LWG4481 <https://wg21.link/LWG4481>`__","Disallow ``chrono::duration<const T, P>``","2026-03 (Croydon)","","","`#189846 <https://github.com/llvm/llvm-project/issues/189846>`__",""
|
||||
"`LWG4481 <https://wg21.link/LWG4481>`__","Disallow ``chrono::duration<const T, P>``","2026-03 (Croydon)","|Complete|","23","`#189846 <https://github.com/llvm/llvm-project/issues/189846>`__",""
|
||||
"`LWG4483 <https://wg21.link/LWG4483>`__","Multidimensional arrays are not supported by ``meta::reflect_constant_array`` and related functions","2026-03 (Croydon)","","","`#189847 <https://github.com/llvm/llvm-project/issues/189847>`__",""
|
||||
"`LWG4485 <https://wg21.link/LWG4485>`__","Move specification for ``task::stop_token_type``","2026-03 (Croydon)","","","`#189848 <https://github.com/llvm/llvm-project/issues/189848>`__",""
|
||||
"`LWG4486 <https://wg21.link/LWG4486>`__","``integral-constant-like`` and ``constexpr-wrapper-like`` exposition-only concept duplication","2026-03 (Croydon)","","","`#189849 <https://github.com/llvm/llvm-project/issues/189849>`__",""
|
||||
|
|
|
|||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <__type_traits/enable_if.h>
|
||||
#include <__type_traits/is_convertible.h>
|
||||
#include <__type_traits/is_floating_point.h>
|
||||
#include <__type_traits/is_unqualified.h>
|
||||
#include <limits>
|
||||
#include <ratio>
|
||||
|
||||
|
|
@ -164,6 +165,7 @@ template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duratio
|
|||
|
||||
template <class _Rep, class _Period>
|
||||
class duration {
|
||||
static_assert(__is_unqualified_v<_Rep>, "A duration representation cannot be qualified");
|
||||
static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration");
|
||||
static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio");
|
||||
static_assert(_Period::num > 0, "duration period must be positive");
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ public:
|
|||
template <class Rep, class Period = ratio<1>>
|
||||
class duration
|
||||
{
|
||||
static_assert(__is_unqualified_v<Rep>, "A duration representation cannot be qualified");
|
||||
static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
|
||||
static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
|
||||
static_assert(Period::num > 0, "duration period must be positive");
|
||||
|
|
|
|||
27
libcxx/test/std/time/time.duration/duration.verify.cpp
Normal file
27
libcxx/test/std/time/time.duration/duration.verify.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <chrono>
|
||||
|
||||
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
|
||||
|
||||
// LWG 4481
|
||||
// A program that instantiates duration with a cv-qualified Rep is ill-formed.
|
||||
|
||||
#include <chrono>
|
||||
|
||||
void test() {
|
||||
// expected-error-re@*:* {{static assertion failed {{.*}}A duration representation cannot be qualified}}
|
||||
(void)sizeof(std::chrono::duration<const int>);
|
||||
|
||||
// expected-error-re@*:* {{static assertion failed {{.*}}A duration representation cannot be qualified}}
|
||||
(void)sizeof(std::chrono::duration<volatile int>);
|
||||
|
||||
// expected-error-re@*:* {{static assertion failed {{.*}}A duration representation cannot be qualified}}
|
||||
(void)sizeof(std::chrono::duration<const volatile int>);
|
||||
}
|
||||
Loading…
Reference in a new issue