Skip to content

Commit a10bf11

Browse files
committed
[libc++] Add warning groups to diagnose_if when available
1 parent 6e57326 commit a10bf11

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
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_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_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_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_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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,10 +1151,14 @@ typedef __char32_t char32_t;
11511151
# define _LIBCPP_NO_DESTROY
11521152
# endif
11531153

1154-
# if __has_attribute(__diagnose_if__)
1155-
# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1156-
# else
1157-
# define _LIBCPP_DIAGNOSE_WARNING(...)
1154+
# if defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 2010
1155+
# define _LIBCPP_DIAGNOSE_IF(warning_group, default_severity, message, ...) \
1156+
__attribute__((__diagnose_if__(__VA_ARGS__, message, default_severity, warning_group)))
1157+
# elif __has_attribute(__diagnose_if__)
1158+
# define _LIBCPP_DIAGNOSE_IF(warning_group, default_severity, message, ...) \
1159+
__attribute__((__diagnose_if__(__VA_ARGS__, message, "warning")))
1160+
# else
1161+
# define _LIBCPP_DIAGNOSE_IF(warning_group, default_severity, message, ...)
11581162
# endif
11591163

11601164
# if __has_cpp_attribute(_Clang::__lifetimebound__)

libcxx/include/__filesystem/path.h

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

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

libcxx/include/__hash_table

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

651651
template <class _Key, class _Hash, class _Equal>
652652
#ifndef _LIBCPP_CXX03_LANG
653-
_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Equal const&, _Key const&, _Key const&>,
654-
"the specified comparator type does not provide a viable const call operator")
655-
_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Hash const&, _Key const&>,
656-
"the specified hash functor does not provide a viable const call operator")
653+
_LIBCPP_DIAGNOSE_IF("pedantic",
654+
"warning",
655+
"the specified comparator type does not provide a viable const call operator",
656+
!__is_invocable_v<_Equal const&, _Key const&, _Key const&>)
657+
_LIBCPP_DIAGNOSE_IF("pedantic",
658+
"warning",
659+
"the specified hash functor does not provide a viable const call operator",
660+
!__is_invocable_v<_Hash const&, _Key const&>)
657661
#endif
658662
typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
659663
__diagnose_unordered_container_requirements(int);

libcxx/include/__tree

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

877877
template <class _Tp, class _Compare>
878878
#ifndef _LIBCPP_CXX03_LANG
879-
_LIBCPP_DIAGNOSE_WARNING(!__is_invocable_v<_Compare const&, _Tp const&, _Tp const&>,
880-
"the specified comparator type does not provide a viable const call operator")
879+
_LIBCPP_DIAGNOSE_IF("pedantic",
880+
"warning",
881+
"the specified comparator type does not provide a viable const call operator",
882+
!__is_invocable_v<_Compare const&, _Tp const&, _Tp const&>)
881883
#endif
882884
int __diagnose_non_const_comparator();
883885

0 commit comments

Comments
 (0)