On Wed, 17 Dec 2025 at 10:34, Tomasz Kamiński <[email protected]> wrote:
>
> Defining the new implementation inside the _V2 inline namespace,
> would guaranteed TUs using old definition (GCC-15 or ones defining
> _GLIBCXX_USE_OLD_GENERATE_CANONICAL) will observe old behavior
> (call old implementation) when linked against TUs using new
> implementation.
>
> This updates random/pr60037-neg.cc to accept static assertion
> with a given message on any line number. Preventing need for
> constant updates.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/random.h (generate_canonical)
> [!_GLIBCXX_USE_OLD_GENERATE_CANONICAL]: Define inside
> _V2 inline namespace.
> * include/bits/random.tcc (generate_canonical)
> [!_GLIBCXX_USE_OLD_GENERATE_CANONICAL]: Likewise.
> * testsuite/26_numerics/random/pr60037-neg.cc: Make
> test independed on line of which static assert is placed.
"independent of line on which"
> ---
> Testing on x86_64-linux. OK for trunk when tests passes?
>
> libstdc++-v3/include/bits/random.h | 6 ++++++
> libstdc++-v3/include/bits/random.tcc | 3 ++-
> libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc | 4 +---
> 3 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/random.h
> b/libstdc++-v3/include/bits/random.h
> index ebc863e8453..5a959ed6ebe 100644
> --- a/libstdc++-v3/include/bits/random.h
> +++ b/libstdc++-v3/include/bits/random.h
> @@ -51,6 +51,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
> // std::uniform_random_bit_generator is defined in
> <bits/uniform_int_dist.h>
>
> +#ifndef _GLIBCXX_USE_OLD_GENERATE_CANONICAL
> +_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
> +#endif
> /**
> * @brief A function template for converting the output of a (integral)
> * uniform random number generator to a floatng point result in the range
> @@ -60,6 +63,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> typename _UniformRandomNumberGenerator>
> _RealType
> generate_canonical(_UniformRandomNumberGenerator& __g);
> +#ifndef _GLIBCXX_USE_OLD_GENERATE_CANONICAL
> +_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
> +#endif
>
> /// @cond undocumented
> // Implementation-space details.
> diff --git a/libstdc++-v3/include/bits/random.tcc
> b/libstdc++-v3/include/bits/random.tcc
> index 053307519b4..4ff5e3e1f64 100644
> --- a/libstdc++-v3/include/bits/random.tcc
> +++ b/libstdc++-v3/include/bits/random.tcc
> @@ -3480,6 +3480,7 @@ namespace __detail
> #pragma GCC diagnostic push
> #pragma GCC diagnostic ignored "-Wc++14-extensions" // for variable templates
> #pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
> +_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
>
> // This version is used when Urbg::max()-Urbg::min() is a power of
> // two less 1, the norm in real programs. It works by calling urng()
> @@ -3700,7 +3701,7 @@ namespace __detail
> }
> }
> }
> -
> +_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
> #pragma GCC diagnostic pop
>
> #else // _GLIBCXX_USE_OLD_GENERATE_CANONICAL
> diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
> b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
> index 13c4dc8724a..b7f9711f47f 100644
> --- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
> +++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc
> @@ -10,7 +10,5 @@ std::__detail::_Adaptor<std::mt19937, unsigned long>
> aurng(urng);
> auto x = std::generate_canonical<std::size_t,
> std::numeric_limits<std::size_t>::digits>(urng);
>
> -// { dg-error "static assertion failed: template argument must be a floating
> point type" "" { target *-*-* } 271 }
> -
> -// { dg-error "static assertion failed: template argument must be a floating
> point type" "" { target *-*-* } 3650 }
> +// { dg-error "static assertion failed: template argument must be a floating
> point type" "" { target *-*-* } 0 }
>
> --
> 2.52.0
>