Skip to content

Commit f7c64c3

Browse files
committed
[libc++] Add warning groups to diagnose_if when available
1 parent 411e61d commit f7c64c3

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

libcxx/include/__atomic/check_memory_order.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,31 @@
1616
#endif
1717

1818
#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
19-
_LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || __m == memory_order_acquire || __m == memory_order_acq_rel, \
20-
"memory order argument to atomic operation is invalid")
19+
_LIBCPP_LEGACY_DIAGNOSE_IF( \
20+
"atomic-memory-ordering", \
21+
"warning", \
22+
"memory order argument to atomic operation is invalid", \
23+
__m == memory_order_consume || __m == memory_order_acquire || __m == memory_order_acq_rel)
2124

2225
#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
23-
_LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \
24-
"memory order argument to atomic operation is invalid")
26+
_LIBCPP_LEGACY_DIAGNOSE_IF( \
27+
"atomic-memory-ordering", \
28+
"warning", \
29+
"memory order argument to atomic operation is invalid", \
30+
__m == memory_order_release || __m == memory_order_acq_rel)
2531

2632
#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
27-
_LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || __f == memory_order_acq_rel, \
28-
"memory order argument to atomic operation is invalid")
33+
_LIBCPP_LEGACY_DIAGNOSE_IF( \
34+
"atomic-memory-ordering", \
35+
"warning", \
36+
"memory order argument to atomic operation is invalid", \
37+
__f == memory_order_release || __f == memory_order_acq_rel)
2938

3039
#define _LIBCPP_CHECK_WAIT_MEMORY_ORDER(__m) \
31-
_LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || __m == memory_order_acq_rel, \
32-
"memory order argument to atomic operation is invalid")
40+
_LIBCPP_LEGACY_DIAGNOSE_IF( \
41+
"atomic-memory-ordering", \
42+
"warning", \
43+
"memory order argument to atomic operation is invalid", \
44+
__m == memory_order_release || __m == memory_order_acq_rel)
3345

3446
#endif // _LIBCPP___ATOMIC_CHECK_MEMORY_ORDER_H

libcxx/include/__config

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,16 +1075,19 @@ typedef __char32_t char32_t;
10751075
# define _LIBCPP_NO_DESTROY
10761076
# endif
10771077

1078-
# if __has_attribute(__diagnose_if__)
1079-
# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1080-
# else
1081-
# define _LIBCPP_DIAGNOSE_WARNING(...)
1082-
# endif
1083-
1078+
// TODO: Remove _LIBCPP_LEGACY_DIAGNOSE_IF once all compilers are based on at least Clang 20
10841079
# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_APPLE_CLANG_VER) && \
10851080
(!defined(_LIBCPP_CLANG_VER) || _LIBCPP_CLANG_VER >= 2001)
10861081
# define _LIBCPP_DIAGNOSE_IF(...) __attribute__((__diagnose_if__(__VA_ARGS__)))
1082+
# define _LIBCPP_LEGACY_DIAGNOSE_IF(warning_group, default_severity, message, ...) \
1083+
__attribute__((__diagnose_if__(__VA_ARGS__, message, default_severity, warning_group)))
10871084
# else
1085+
# if __has_attribute(__diagnose_if__)
1086+
# define _LIBCPP_LEGACY_DIAGNOSE_IF(warning_group, default_severity, message, ...) \
1087+
__attribute__((__diagnose_if__(__VA_ARGS__, message, "warning")))
1088+
# else
1089+
# define _LIBCPP_LEGACY_DIAGNOSE_IF(warning_group, default_severity, message, ...)
1090+
# endif
10881091
# define _LIBCPP_DIAGNOSE_IF(...)
10891092
# endif
10901093

libcxx/include/__filesystem/path.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ class _LIBCPP_EXPORTED_FROM_ABI path {
521521
return *this;
522522
}
523523

524-
// FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src
524+
// FIXME: Use _LIBCPP_DIAGNOSE_IF to produce a diagnostic when __src
525525
// is known at compile time to be "/' since the user almost certainly intended
526526
// to append a separator instead of overwriting the path with "/"
527527
template <class _Source>

libcxx/include/__hash_table

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,14 @@ struct __enforce_unordered_container_requirements {
619619

620620
template <class _Key, class _Hash, class _Equal>
621621
#ifndef _LIBCPP_CXX03_LANG
622-
_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Equal const&, _Key const&, _Key const&>,
623-
"the specified comparator type does not provide a viable const call operator")
624-
_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Hash const&, _Key const&>,
625-
"the specified hash functor does not provide a viable const call operator")
622+
_LIBCPP_LEGACY_DIAGNOSE_IF("discard-qual",
623+
"warning",
624+
"the specified comparator type does not provide a viable const call operator",
625+
!__is_invocable_v<_Equal const&, _Key const&, _Key const&>)
626+
_LIBCPP_LEGACY_DIAGNOSE_IF("discard-qual",
627+
"warning",
628+
"the specified hash functor does not provide a viable const call operator",
629+
!__is_invocable_v<_Hash const&, _Key const&>)
626630
#endif
627631
typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
628632
__diagnose_unordered_container_requirements(int);

libcxx/include/__tree

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,10 @@ private:
776776

777777
template <class _Tp, class _Compare>
778778
#ifndef _LIBCPP_CXX03_LANG
779-
_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Compare const&, _Tp const&, _Tp const&>,
780-
"the specified comparator type does not provide a viable const call operator")
779+
_LIBCPP_LEGACY_DIAGNOSE_IF("discard-qual",
780+
"warning",
781+
"the specified comparator type does not provide a viable const call operator",
782+
!__is_invocable_v<_Compare const&, _Tp const&, _Tp const&>)
781783
#endif
782784
int __diagnose_non_const_comparator();
783785

0 commit comments

Comments
 (0)