[libcxx-commits] [libcxx] [libc++] Drop -Wno-user-defined-literals when running the test suite (PR #167073)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 7 18:08:09 PST 2025
https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/167073
I'd like to reduce the number of warnings we disable when running the test suite, and these two seem like obvious targets for removal since it's really easy to just guard the "offending" code with pragmas.
>From 41117214f9219196e04091d82e59286466ad8b25 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 7 Nov 2025 16:06:10 -1000
Subject: [PATCH] [libc++] Drop -Wno-user-defined-literals when running the
test suite
I'd like to reduce the number of warnings we disable when running the
test suite, and these two seem like obvious targets for removal since
it's really easy to just guard the "offending" code with pragmas.
---
libcxx/include/__chrono/duration.h | 6 ++++++
libcxx/include/__chrono/literals.h | 8 ++++++++
libcxx/include/complex | 8 ++++++++
libcxx/include/string | 8 ++++++++
libcxx/include/string_view | 8 ++++++++
libcxx/utils/libcxx/test/params.py | 4 ----
6 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__chrono/duration.h b/libcxx/include/__chrono/duration.h
index 57fa64d650068..270bad253c139 100644
--- a/libcxx/include/__chrono/duration.h
+++ b/libcxx/include/__chrono/duration.h
@@ -481,6 +481,10 @@ operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2
inline namespace literals {
inline namespace chrono_literals {
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wuser-defined-literals")
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wliteral-suffix")
+
_LIBCPP_HIDE_FROM_ABI constexpr chrono::hours operator""h(unsigned long long __h) {
return chrono::hours(static_cast<chrono::hours::rep>(__h));
}
@@ -529,6 +533,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, nano> operator""ns
return chrono::duration<long double, nano>(__ns);
}
+_LIBCPP_DIAGNOSTIC_POP
+
} // namespace chrono_literals
} // namespace literals
diff --git a/libcxx/include/__chrono/literals.h b/libcxx/include/__chrono/literals.h
index 89800440edf43..2268c38676d31 100644
--- a/libcxx/include/__chrono/literals.h
+++ b/libcxx/include/__chrono/literals.h
@@ -24,6 +24,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
inline namespace literals {
inline namespace chrono_literals {
+
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wuser-defined-literals")
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wliteral-suffix")
+
_LIBCPP_HIDE_FROM_ABI constexpr chrono::day operator""d(unsigned long long __d) noexcept {
return chrono::day(static_cast<unsigned>(__d));
}
@@ -31,6 +36,9 @@ _LIBCPP_HIDE_FROM_ABI constexpr chrono::day operator""d(unsigned long long __d)
_LIBCPP_HIDE_FROM_ABI constexpr chrono::year operator""y(unsigned long long __y) noexcept {
return chrono::year(static_cast<int>(__y));
}
+
+_LIBCPP_DIAGNOSTIC_POP
+
} // namespace chrono_literals
} // namespace literals
diff --git a/libcxx/include/complex b/libcxx/include/complex
index d8ec3d95c10ed..1550bc81f1626 100644
--- a/libcxx/include/complex
+++ b/libcxx/include/complex
@@ -1443,6 +1443,11 @@ _LIBCPP_HIDE_FROM_ABI constexpr const _Xp&& get(const complex<_Xp>&& __z) noexce
// Literal suffix for complex number literals [complex.literals]
inline namespace literals {
inline namespace complex_literals {
+
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wuser-defined-literals")
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wliteral-suffix")
+
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<long double> operator""il(long double __im) { return {0.0l, __im}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<long double> operator""il(unsigned long long __im) {
@@ -1464,6 +1469,9 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr complex<float> operator""if(long double _
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<float> operator""if(unsigned long long __im) {
return {0.0f, static_cast<float>(__im)};
}
+
+_LIBCPP_DIAGNOSTIC_POP
+
} // namespace complex_literals
} // namespace literals
# endif
diff --git a/libcxx/include/string b/libcxx/include/string
index ede42467b99fe..f1083cf624792 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -3946,6 +3946,11 @@ erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred) {
// Literal suffixes for basic_string [basic.string.literals]
inline namespace literals {
inline namespace string_literals {
+
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wuser-defined-literals")
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wliteral-suffix")
+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<char>
operator""s(const char* __str, size_t __len) {
return basic_string<char>(__str, __len);
@@ -3973,6 +3978,9 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<char32_t
operator""s(const char32_t* __str, size_t __len) {
return basic_string<char32_t>(__str, __len);
}
+
+_LIBCPP_DIAGNOSTIC_POP
+
} // namespace string_literals
} // namespace literals
diff --git a/libcxx/include/string_view b/libcxx/include/string_view
index 5ecaa3de7deba..5a55cc92b5897 100644
--- a/libcxx/include/string_view
+++ b/libcxx/include/string_view
@@ -924,6 +924,11 @@ struct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_
# if _LIBCPP_STD_VER >= 14
inline namespace literals {
inline namespace string_view_literals {
+
+_LIBCPP_DIAGNOSTIC_PUSH
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wuser-defined-literals")
+_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wliteral-suffix")
+
inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char> operator""sv(const char* __str, size_t __len) noexcept {
return basic_string_view<char>(__str, __len);
}
@@ -951,6 +956,9 @@ inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char32_t>
operator""sv(const char32_t* __str, size_t __len) noexcept {
return basic_string_view<char32_t>(__str, __len);
}
+
+_LIBCPP_DIAGNOSTIC_POP
+
} // namespace string_view_literals
} // namespace literals
# endif
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index c02d6df1c47a4..44578ebe0e582 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -35,10 +35,6 @@
# GCC warns about places where we might want to add sized allocation/deallocation
# functions, but we know better what we're doing/testing in the test suite.
"-Wno-sized-deallocation",
- # Turn off warnings about user-defined literals with reserved suffixes. Those are
- # just noise since we are testing the Standard Library itself.
- "-Wno-literal-suffix", # GCC
- "-Wno-user-defined-literals", # Clang
# GCC warns about this when TEST_IS_CONSTANT_EVALUATED is used on a non-constexpr
# function. (This mostly happens in C++11 mode.)
# TODO(mordante) investigate a solution for this issue.
More information about the libcxx-commits
mailing list