Skip to content

Conversation

@ldionne
Copy link
Member

@ldionne ldionne commented Nov 8, 2025

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.

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.
@ldionne ldionne requested a review from a team as a code owner November 8, 2025 02:08
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2025

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/167073.diff

6 Files Affected:

  • (modified) libcxx/include/__chrono/duration.h (+6)
  • (modified) libcxx/include/__chrono/literals.h (+8)
  • (modified) libcxx/include/complex (+8)
  • (modified) libcxx/include/string (+8)
  • (modified) libcxx/include/string_view (+8)
  • (modified) libcxx/utils/libcxx/test/params.py (-4)
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.

@ldionne
Copy link
Member Author

ldionne commented Nov 8, 2025

Note that this came up while reducing a reproducer in one of our tests. I removed a bunch of warning flags from the command-line and noticed that our headers started emitting large numbers of these warnings. I think it's worth handling the low hanging fruit in the headers directly.

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the general goal is great, but I'm not convinced these diagnostics are the right ones to enable. These seem to only cause false positives, and I can really imagine a case where we'd accidentally write a UDL that's reserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants