[RFC] Add gnu::diagnose_as attribute

Jonathan Wakely jwakely@redhat.com
Tue Apr 27 09:46:48 GMT 2021

On 23/04/21 17:16 +0200, Matthias Kretz wrote:
>before requesting comments on the implementation of this patch, I'd like to
>know if there's interest in making use of it at all.
>In a nutshell, this solves the problem of bad signal-to-noise ratio with TS
>implementations and potentially implementation-internal types.
>I've been using the diagnose_as attribute on my parallelism_v2 simd
>implementation for two months now, and it significantly improved my
>productivity. Like this:
>namespace std _GLIBCXX_VISIBILITY(default)
>  namespace experimental
>  {
>    inline namespace parallelism_v2 [[__gnu__::__diagnose_as__("stdₓ")]]
>    {
>      namespace simd_abi [[__gnu__::__diagnose_as__("simd_abi")]]
>      {
>        struct [[__gnu__::__diagnose_as__("scalar")]] _Scalar;
>        using scalar = _Scalar;
>        template <int _Np>
>          struct [[__gnu__::__diagnose_as__("fixed_size")]] _Fixed;
>        template <int _Np>
>          using fixed_size = _Fixed<_Np>;
>1. __PRETTY_FUNCTION__ in my test output:
>   PASS: void invoke_test(int) [with V = stdₓ::simd<double,
>simd_abi::_VecBuiltin<16> >; <template-parameter-1-2> = stdₓ::simd<double,
>simd_abi::_VecBuiltin<16> >]
>   instead of
>   PASS: void invoke_test(int) [with V =
>std::experimental::parallelism_v2::simd_abi::_VecBuiltin<16> >; <template-
>parameter-1-2> = std::experimental::parallelism_v2::simd<double,
>std::experimental::parallelism_v2::simd_abi::_VecBuiltin<16> >]
>2. Error messages:
>   required from 'static constexpr stdₓ::_SimdWrapper<_Tp, _Np>
>stdₓ::_SimdImplBuiltin<_Abi, <template-parameter-1-2>
>>::_S_fma(stdₓ::_SimdWrapper<_Tp, _Np>, stdₓ::_SimdWrapper<_Tp, _Np>,
>stdₓ::_SimdWrapper<_Tp, _Np>) [with _Tp = double; long unsigned int _Np = 2;
>_Abi = simd_abi::_VecBuiltin<16>; <template-parameter-1-2> =
>stdₓ::__detail::_MachineFlagsTemplate<31, 9>]'
>   instead of
>   required from 'static constexpr
>std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>
>std::experimental::parallelism_v2::_SimdImplBuiltin<_Abi, <template-
>parameter-1-2> >::_S_fma(std::experimental::parallelism_v2::_SimdWrapper<_Tp,
>_Np>, std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>,
>std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>) [with _Tp = double;
>long unsigned int _Np = 2; _Abi =
>std::experimental::parallelism_v2::simd_abi::_VecBuiltin<16>; <template-
>parameter-1-2> =
>std::experimental::parallelism_v2::__detail::_MachineFlagsTemplate<31, 9>]'
>Since the main user of the attribute would be the standard library (I
>believe), this patch only makes sense to pursue if there's interest in using
>it in libstdc++. I'd like to use it for stdₓ::simd. Would you accept such a

I think it's a great idea and would like to use it for all the TS
implementations where there is some inline namespace that the user
doesn't care about. std::experimental::fundamentals_v1:: would be much
better as just std::experimental::, or something like std::[LFTS]::.

My gut feeling is that something that isn't valid C++ syntax would
make it clear you can't just copy&paste the qualified-name from the
diagnostics to the code, so some identifier in square brackets would
work. But I'm willing to be persuaded that doesn't matter.

>patch? I guess using unicode in the alias name would not be acceptable,

I'm not wild about the UTF-8 characters, but we could define a macro
for the attribute, and have:

# define _GLIBCXX_STDX [[__gnu__::__diagnose_as__ ("std\u2093")]]
# define _GLIBCXX_STDX [[__gnu__::__diagnose_as__ ("std::[exp]")]]

(The universal character name ensures the header can still be used
with -finput-charset=ascii and similar, but still prints "stdₓ" in the

More information about the Libstdc++ mailing list