[libcxx-commits] [libcxx] [libc++] Test LWG4113: Disallow `has_unique_object_representations<Incomplete[]>` (PR #169446)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 11 05:48:30 PDT 2026


================
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++17
+
+// <type_traits>
+
+// has_unique_object_representations
+
+// Verify that has_unique_object_representations(_v) rejects incomplete class and enumeration types and arrays thereof.
+
+#include <type_traits>
+
+class IC;
+
+constexpr bool v1 = std::has_unique_object_representations<IC>::value;
+constexpr bool v2 = std::has_unique_object_representations<IC[]>::value;
+constexpr bool v3 = std::has_unique_object_representations<IC[1]>::value;
+constexpr bool v4 = std::has_unique_object_representations<IC[][1]>::value;
+
+constexpr bool v5 = std::has_unique_object_representations_v<IC>;
+constexpr bool v6 = std::has_unique_object_representations_v<IC[]>;
+constexpr bool v7 = std::has_unique_object_representations_v<IC[1]>;
+constexpr bool v8 = std::has_unique_object_representations_v<IC[][1]>;
+
+// expected-error@*:* 8 {{incomplete type 'IC' used in type trait expression}}
+
+enum E {
+  v9  = std::has_unique_object_representations<E>::value,
+  v10 = std::has_unique_object_representations<E[]>::value,
+  v11 = std::has_unique_object_representations<E[1]>::value,
+  v12 = std::has_unique_object_representations<E[][1]>::value,
+
+  v13 = std::has_unique_object_representations_v<E>,
+  v14 = std::has_unique_object_representations_v<E[]>,
+  v15 = std::has_unique_object_representations_v<E[1]>,
+  v16 = std::has_unique_object_representations_v<E[][1]>,
+
+// TODO: Remove the guard once https://llvm.org/PR169472 is resolved.
+#ifndef _MSC_VER // In Clang-cl mode, E is incorrectly considered complete here.
----------------
frederick-vs-ja wrote:

Oops, this doesn't work. `test_macros.h` defines `TEST_COMPILER_CLANG` but not `TEST_COMPILER_MSVC` in MSVC mode.

https://github.com/llvm/llvm-project/blob/9d3f81dadfcd509eadd16213a7f428e081214147/libcxx/test/support/test_macros.h#L75-L86

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


More information about the libcxx-commits mailing list