[libcxx-commits] [libcxx] [libc++][chrono] Implement LWG 4481: disallow chrono::duration<const T, P> (PR #207558)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 5 08:12:12 PDT 2026


================
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23
+
+// <chrono>
+
+// LWG 4481
+// A program that instantiates duration with a cv-qualified Rep is ill-formed.
+
+#include <chrono>
+
+void test_const() {
+  // expected-error-re@*:* {{static assertion failed {{.*}}A duration representation cannot be cv-qualified}}
+  (void)sizeof(std::chrono::duration<const int>);
+}
+
+void test_volatile() {
+  // expected-error-re@*:* {{static assertion failed {{.*}}A duration representation cannot be cv-qualified}}
+  (void)sizeof(std::chrono::duration<volatile int>);
+}
+
+void test_const_volatile() {
+  // expected-error-re@*:* {{static assertion failed {{.*}}A duration representation cannot be cv-qualified}}
+  (void)sizeof(std::chrono::duration<const volatile int>);
+}
----------------
emmett2020 wrote:

Thank you! I moved them into one function.

https://github.com/llvm/llvm-project/pull/207558


More information about the libcxx-commits mailing list