[libcxx-commits] [libcxx] [libc++][test] Guard use of `[[clang::trivial_abi]]` (PR #211736)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 23 23:27:26 PDT 2026


https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/211736

This patch makes `[[clang::trivial_abi]]` used only if supported to address MSVC's warning C5030.

The `TEST_CLANG_TRIVIAL_ABI` macro is not promoted to `test_macros.h` because it is currently used only in one file. We may promote it later.

Fixes #182392.

>From 96cc0f22868c171ce4e9af95a625ab869e566517 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Fri, 24 Jul 2026 14:25:43 +0800
Subject: [PATCH] [libc++][test] Guard use of `[[clang::trivial_abi]]`

This patch makes `[[clang::trivial_abi]]` used only if supported to
address MSVC's warning C5030.

The `TEST_CLANG_TRIVIAL_ABI` macro is not promoted to `test_macros.h`
because it is currently used only in one file. We may promote it later.
---
 .../sequences/vector/trivial_relocation.pass.cpp         | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/std/containers/sequences/vector/trivial_relocation.pass.cpp b/libcxx/test/std/containers/sequences/vector/trivial_relocation.pass.cpp
index fbd597d07d6e3..1ac46b182f680 100644
--- a/libcxx/test/std/containers/sequences/vector/trivial_relocation.pass.cpp
+++ b/libcxx/test/std/containers/sequences/vector/trivial_relocation.pass.cpp
@@ -19,11 +19,18 @@
 
 #include "test_macros.h"
 
+// The test should pass regardless of whether the compiler supports [[clang::trivial_abi]].
+#if __has_cpp_attribute(clang::trivial_abi)
+#  define TEST_CLANG_TRIVIAL_ABI [[clang::trivial_abi]]
+#else
+#  define TEST_CLANG_TRIVIAL_ABI
+#endif
+
 struct Tracker {
   std::size_t move_constructs = 0;
 };
 
-struct [[clang::trivial_abi]] Inner {
+struct TEST_CLANG_TRIVIAL_ABI Inner {
   TEST_CONSTEXPR_CXX20 explicit Inner(Tracker* tracker) : tracker_(tracker) {}
   TEST_CONSTEXPR_CXX20 Inner(const Inner& rhs) : tracker_(rhs.tracker_) { tracker_->move_constructs += 1; }
   TEST_CONSTEXPR_CXX20 Inner(Inner&& rhs) : tracker_(rhs.tracker_) { tracker_->move_constructs += 1; }



More information about the libcxx-commits mailing list