-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++][RFC] Refactor attributes to [[attribute_macro]] #130099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| extern template class __attribute__((__libcpp_deprecated_in_cxx20())) | ||
| _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20 | ||
| extern template class _LIBCPP_DEPRECATED_IN_CXX20 | ||
| extern template class __attribute__((__libcpp_deprecated_in_cxx20())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I had to use __attribute__ here, since the [[]] version isn't allowed anywhere. This is the only place though.
|
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesThis is mostly a different way to add attributes everywhere, but I think it makes the code quite a bit easier to read for a few reasons:
Patch is 388.65 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/130099.diff 274 Files Affected:
diff --git a/libcxx/.clang-format b/libcxx/.clang-format
index f548119652c19..41a9af50ae1d9 100644
--- a/libcxx/.clang-format
+++ b/libcxx/.clang-format
@@ -24,12 +24,6 @@ AttributeMacros: [
'_LIBCPP_CONSTEXPR_SINCE_CXX23',
'_LIBCPP_CONSTEXPR',
'_LIBCPP_CONSTINIT',
- '_LIBCPP_DEPRECATED_IN_CXX11',
- '_LIBCPP_DEPRECATED_IN_CXX14',
- '_LIBCPP_DEPRECATED_IN_CXX17',
- '_LIBCPP_DEPRECATED_IN_CXX20',
- '_LIBCPP_DEPRECATED_IN_CXX23',
- '_LIBCPP_DEPRECATED',
'_LIBCPP_DISABLE_EXTENSION_WARNING',
'_LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION',
'_LIBCPP_EXPORTED_FROM_ABI',
@@ -45,7 +39,6 @@ AttributeMacros: [
'_LIBCPP_OVERRIDABLE_FUNC_VIS',
'_LIBCPP_STANDALONE_DEBUG',
'_LIBCPP_TEMPLATE_DATA_VIS',
- '_LIBCPP_TEMPLATE_VIS',
'_LIBCPP_THREAD_SAFETY_ANNOTATION',
'_LIBCPP_USING_IF_EXISTS',
'_LIBCPP_WEAK',
diff --git a/libcxx/docs/DesignDocs/VisibilityMacros.rst b/libcxx/docs/DesignDocs/VisibilityMacros.rst
index 83a9a62942bc9..07b1de0d5b7b3 100644
--- a/libcxx/docs/DesignDocs/VisibilityMacros.rst
+++ b/libcxx/docs/DesignDocs/VisibilityMacros.rst
@@ -64,7 +64,7 @@ Visibility Macros
ABI, we should create a new _LIBCPP_HIDE_FROM_ABI_AFTER_XXX macro, and we can
use it to start removing symbols from the ABI after that stable version.
-**_LIBCPP_TEMPLATE_VIS**
+**__libcpp_template_vis**
Mark a type's typeinfo and vtable as having default visibility.
This macro has no effect on the visibility of the type's member functions.
@@ -80,7 +80,7 @@ Visibility Macros
an extern template declaration as being exported by the libc++ library.
This attribute must be specified on all extern class template declarations.
- This macro is used to override the `_LIBCPP_TEMPLATE_VIS` attribute
+ This macro is used to override the `__libcpp_template_vis` attribute
specified on the primary template and to export the member functions produced
by the explicit instantiation in the dylib.
diff --git a/libcxx/include/__algorithm/shuffle.h b/libcxx/include/__algorithm/shuffle.h
index 7177fbb469ba7..db1eba7810c66 100644
--- a/libcxx/include/__algorithm/shuffle.h
+++ b/libcxx/include/__algorithm/shuffle.h
@@ -92,7 +92,7 @@ class _LIBCPP_EXPORTED_FROM_ABI __rs_default {
_LIBCPP_EXPORTED_FROM_ABI __rs_default __rs_get();
template <class _RandomAccessIterator>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void
+_LIBCPP_HIDE_FROM_ABI [[__libcpp_deprecated_in_cxx14("std::shuffle should be used instead")]] void
random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) {
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef uniform_int_distribution<ptrdiff_t> _Dp;
@@ -110,7 +110,7 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) {
}
template <class _RandomAccessIterator, class _RandomNumberGenerator>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX14 void
+_LIBCPP_HIDE_FROM_ABI [[__libcpp_deprecated_in_cxx14("std::shuffle should be used instead")]] void
random_shuffle(_RandomAccessIterator __first,
_RandomAccessIterator __last,
# ifndef _LIBCPP_CXX03_LANG
diff --git a/libcxx/include/__atomic/atomic.h b/libcxx/include/__atomic/atomic.h
index c65f9afe4f390..8fbd146f650f1 100644
--- a/libcxx/include/__atomic/atomic.h
+++ b/libcxx/include/__atomic/atomic.h
@@ -467,13 +467,13 @@ _LIBCPP_HIDE_FROM_ABI bool atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
// atomic_init
template <class _Tp>
-_LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void
+[[__libcpp_deprecated_in_cxx20()]] _LIBCPP_HIDE_FROM_ABI void
atomic_init(volatile atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
std::__cxx_atomic_init(std::addressof(__o->__a_), __d);
}
template <class _Tp>
-_LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void
+[[__libcpp_deprecated_in_cxx20()]] _LIBCPP_HIDE_FROM_ABI void
atomic_init(atomic<_Tp>* __o, typename atomic<_Tp>::value_type __d) _NOEXCEPT {
std::__cxx_atomic_init(std::addressof(__o->__a_), __d);
}
diff --git a/libcxx/include/__chrono/duration.h b/libcxx/include/__chrono/duration.h
index 941aca6009599..774de3a8eb349 100644
--- a/libcxx/include/__chrono/duration.h
+++ b/libcxx/include/__chrono/duration.h
@@ -32,7 +32,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono {
template <class _Rep, class _Period = ratio<1> >
-class _LIBCPP_TEMPLATE_VIS duration;
+class [[__libcpp_template_vis]] duration;
template <class _Tp>
inline const bool __is_duration_v = false;
@@ -52,7 +52,7 @@ inline const bool __is_duration_v<const volatile duration<_Rep, _Period> > = tru
} // namespace chrono
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
-struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > {
+struct [[__libcpp_template_vis]] common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > {
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, __ratio_gcd<_Period1, _Period2> > type;
};
@@ -107,7 +107,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration duration_cast(const d
}
template <class _Rep>
-struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
+struct [[__libcpp_template_vis]] treat_as_floating_point : is_floating_point<_Rep> {};
#if _LIBCPP_STD_VER >= 17
template <class _Rep>
@@ -115,7 +115,7 @@ inline constexpr bool treat_as_floating_point_v = treat_as_floating_point<_Rep>:
#endif
template <class _Rep>
-struct _LIBCPP_TEMPLATE_VIS duration_values {
+struct [[__libcpp_template_vis]] duration_values {
public:
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT { return _Rep(0); }
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT { return numeric_limits<_Rep>::max(); }
@@ -156,7 +156,7 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<
// duration
template <class _Rep, class _Period>
-class _LIBCPP_TEMPLATE_VIS duration {
+class [[__libcpp_template_vis]] duration {
static_assert(!__is_duration_v<_Rep>, "A duration representation can not be a duration");
static_assert(__is_ratio_v<_Period>, "Second template parameter of duration must be a std::ratio");
static_assert(_Period::num > 0, "duration period must be positive");
diff --git a/libcxx/include/__chrono/formatter.h b/libcxx/include/__chrono/formatter.h
index 7b081f92667b5..0d5b6390df2b9 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -698,7 +698,7 @@ __format_chrono(const _Tp& __value,
} // namespace __formatter
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS __formatter_chrono {
+struct [[__libcpp_template_vis]] __formatter_chrono {
public:
template <class _ParseContext>
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator
@@ -716,7 +716,7 @@ struct _LIBCPP_TEMPLATE_VIS __formatter_chrono {
};
template <class _Duration, __fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::sys_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::sys_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -730,7 +730,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::sys_time<_Duration>, _CharT> : pub
# if _LIBCPP_HAS_EXPERIMENTAL_TZDB
template <class _Duration, __fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::utc_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::utc_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -741,7 +741,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::utc_time<_Duration>, _CharT> : pub
};
template <class _Duration, __fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::tai_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::tai_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -752,7 +752,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::tai_time<_Duration>, _CharT> : pub
};
template <class _Duration, __fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::gps_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::gps_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -766,7 +766,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::gps_time<_Duration>, _CharT> : pub
# endif // _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM
template <class _Duration, __fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::file_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::file_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -777,7 +777,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::file_time<_Duration>, _CharT> : pu
};
template <class _Duration, __fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::local_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::local_time<_Duration>, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -811,7 +811,7 @@ struct formatter<chrono::duration<_Rep, _Period>, _CharT> : public __formatter_c
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::day, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::day, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -822,7 +822,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::day, _CharT> : public __formatter_
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::month, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -833,7 +833,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month, _CharT> : public __formatte
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::year, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -844,7 +844,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year, _CharT> : public __formatter
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::weekday, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -855,7 +855,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday, _CharT> : public __format
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_indexed, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::weekday_indexed, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -866,7 +866,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_indexed, _CharT> : public
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_last, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::weekday_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -877,7 +877,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_last, _CharT> : public __f
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::month_day, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -888,7 +888,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day, _CharT> : public __form
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day_last, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::month_day_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -899,7 +899,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day_last, _CharT> : public _
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::month_weekday, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -910,7 +910,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday, _CharT> : public __
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -921,7 +921,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday_last, _CharT> : publ
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::year_month, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -932,7 +932,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month, _CharT> : public __for
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::year_month_day, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -943,7 +943,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day, _CharT> : public _
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day_last, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::year_month_day_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -954,7 +954,7 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day_last, _CharT> : pub
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]] formatter<chrono::year_month_weekday, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
@@ -965,7 +965,8 @@ struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday, _CharT> : publ
};
template <__fmt_char_type _CharT>
-struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
+struct [[__libcpp_template_vis]]
+formatter<chrono::year_month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base _LIBCPP_NODEBUG = __formatter_chrono<_CharT>;
diff --git a/libcxx/include/__chrono/parser_std_format_spec.h b/libcxx/include/__chrono/parser_std_format_spec.h
index 4df8e603c6bcf..6b72cb78859e3 100644
--- a/libcxx/include/__chrono/parser_std_format_spec.h
+++ b/libcxx/include/__chrono/parser_std_format_spec.h
@@ -139,7 +139,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __validate_time_zone(__flags __flags) {
}
template <class _CharT>
-class _LIBCPP_TEMPLATE_VIS __parser_chrono {
+class [[__libcpp_template_vis]] __parser_chrono {
using _ConstIterator _LIBCPP_NODEBUG = typename basic_format_parse_context<_CharT>::const_iterator;
public:
diff --git a/libcxx/include/__chrono/time_point.h b/libcxx/include/__chrono/time_point.h
index 5e79fa5d257fa..8ca5240bedd9c 100644
--- a/libcxx/include/__chrono/time_point.h
+++ b/libcxx/include/__chrono/time_point.h
@@ -31,7 +31,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono {
template <class _Clock, class _Duration = typename _Clock::duration>
-class _LIBCPP_TEMPLATE_VIS time_point {
+class [[__libcpp_template_vis]] time_point {
static_assert(__is_duration_v<_Duration>, "Second template parameter of time_point must be a std::chrono::duration");
public:
@@ -76,7 +76,7 @@ class _LIBCPP_TEMPLATE_VIS time_point {
} // namespace chrono
template <class _Clock, class _Duration1, class _Duration2>
-struct _LIBCPP_TEMPLATE_VIS
+struct [[__libcpp_template_vis]]
common_type<chrono::time_point<_Clock, _Duration1>, chrono::time_point<_Clock, _Duration2> > {
typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
};
diff --git a/libcxx/include/__compare/common_comparison_category.h b/libcxx/include/__compare/common_comparison_category.h
index 6ddf9b9d45894..30118fd3cf87f 100644
--- a/libcxx/include/__compare/common_comparison_category.h
+++ b/libcxx/include/__compare/common_comparison_category.h
@@ -72,7 +72,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __get_comp_type() {
// [cmp.common], common comparison category type
template <class... _Ts>
-struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
+struct [[__libcpp_template_vis]] common_comparison_category {
using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
};
diff --git a/libcxx/include/__compare/compare_three_way.h b/libcxx/include/__compare/compare_three_way.h
index 01c12076c0d73..c2e6afc4309a3 100644
--- a/libcxx/include/__compare/compare_three_way.h
+++ b/libcxx/include/__compare/compare_three_way.h
@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 20
-struct _LIBCPP_TEMPLATE_VIS compare_three_way {
+struct [[__libcpp_template_vis]] compare_three_way {
template <class _T1, class _T2>
requires three_way_comparable_with<_T1, _T2>
constexpr _LIBCPP_HIDE_FROM_ABI auto operator()(_T1&& __t, _T2&& __u) const
diff --git a/libcxx/include/__compare/compare_three_way_result.h b/libcxx/include/__compare/compare_three_way_result.h
index 6ee2eff00302d..7d870bc647deb 100644
--- a/libcxx/include/__compare/compare_three_way_result.h
+++ b/libcxx/include/__compare/compare_three_way_result.h
@@ -33,7 +33,7 @@ struct _LIBCPP_HIDE_FROM_ABI __compare_three_way_result<
};
template <class _Tp, class _Up = _Tp>
-struct _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS compare_three_way_result
+struct [[__libcpp_template_vis]] _LIBCPP_NO_SPECIALIZATIONS compare_three_way_result
: __compare_three_way_result<_Tp, _Up, void> {};
template <class _Tp, class _Up = _Tp>
diff --git a/libcxx/include/__config b/libcxx/include/__config
index c8224b07a6b81..ff2f6398be8da 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -389,7 +389,7 @@ typedef __char32_t char32_t;
# define _LIBCPP_HIDDEN
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
-# define _LIBCPP_TEMPLATE_VIS
+# define __libcpp_template_vis
# define _LIBCPP_TEMPLATE_DATA_VIS
#...
[truncated]
|
|
|
||
| template <class _Tp> | ||
| _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void | ||
| [[__libcpp_deprecated_in_cxx20()]] _LIBCPP_HIDE_FROM_ABI void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the empty parenthesis required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are required if we want to be able to add a message. I think it'd be better this way to encourage people to add a message, but it's not required for the main change. If that's the hangup I can revert these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to be able to provide a message. However there is not always a replacement in the Standard. So I rather have two macros one for that provides a message and one that doesn't. That avoids the () which looks bad to me.
ldionne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR states a few benefits of this change which mostly revolve around readability. I think I agree with them, once we're past the initial disruption of making a change of this scale and we've gotten used to the new syntax.
I do wonder if the cost of that disruption is worth it though, since the benefits, while nice, seem like a "nice to have". In particular, I think we need to think the following things through:
- Can we apply this syntax to all attributes? If not, then we introduced new inconsistencies in the codebase and I think that greatly reduces the benefit of this change.
- These "attribute" macros can be utilized to apply things that are not pure attributes today. For example,
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VISexpands toinline _LIBCPP_HIDDENsometimes. What do we want to do with this (horrible) macro? Do we have other use cases for this capability of a macro to expand to non-attribute things?
Apart from that, I think that the ability to provide a message to some attributes like the deprecation attributes is great. We should pursue that in a separate patch, and probably before this refactoring since I can see it taking a while.
Finally, about naming. I am a bit conflicted with the choice of naming for this new style of attributes. On the one hand, I think it's a good convention to use _LIBCPP_FOO for macros. It's consistent with what we do everywhere. On the other hand, I do agree that _UPPERCASE makes these macros use up a lot of visual real estate, and I think the code would be more readable with something more low profile. I don't have a fully formed opinion about that yet.
Overall, I think this change may make sense but I'd like us to have answers/positions to the questions/concerns above. We'd also want to make sure that we engage with other frequent contributors to get their opinion on the change since this will touch a lot of things (in a mechanical way).
|
I've looked a few times at the patch to form an opinion, hence the late reaction. I'm not too fond of the attribute syntax, it makes the text longer this means that there fits less on a line. I agree it's nice when the editor does proper syntax highlighting, however I read quite a lot of code during reviewing on GitHub where we have no syntax highlighting. I have the feeling this proposal does not really showcase what the final code looks like, I still see code like I really dislike changing macros to lowercase. This makes it harder for the reader to know when something is or is not a macro. Once we do that for "attributes" there is a precedence to use lowercase macros which I think is not a direction we should move to. Using uppercase macros is the industry standard, so it's easy for new contributors to determine whether or not something is a macro. (Regardless whether we use I agree with @ldionne we should pursue the deprecated diagnostic in a separate patch. I don't mind to see that in the example I requested above. |
This is mostly a different way to add attributes everywhere, but I think it makes the code quite a bit easier to read for a few reasons:
This is only changing a few attributes for now so people can see how it'd look.