https://gcc.gnu.org/g:8372629e97f8818c7a13197ab270c11248364b12
commit r16-6213-g8372629e97f8818c7a13197ab270c11248364b12 Author: Jonathan Wakely <[email protected]> Date: Wed Dec 17 10:17:37 2025 +0000 libstdc++: Move new std::generate_canonical to inline namespace This ensures that the new definition of std::generate_canonical has a different mangled name from the old one, so that TUs compiled with GCC 16 will be sure to use the new definition, even if the linker also sees a symbol instantiated from the old definition. We use the same _V2 inline namespace as used elsewhere (std::_V2::condition_variable, std::_V2::__rotate, and std::chrono::_V2::system_clock), and use a macro to add it conditionally so that it's not used for the ABI-unstable gnu-versioned-namespace configuration. We can simplify the 26_numerics/random/pr60037-neg.cc test to only use one dg-error without a line number, so that it matches any of the three relevant static_assert failures for this test: the one from _Adaptor in <bits/random.h> and the ones from the new and old definitions of std::generate_canonical in <bits/random.tcc>. Without this change, the line number for the dg-error matching the <bits/random.tcc> error depends on the _GLIBCXX_USE_OLD_GENERATE_CANONICAL macro, which is awkward to depend on in the test (because DejaGnu sees all dg-error directives, it doesn't care if they're guarded by #ifdef preprocessor checks). libstdc++-v3/ChangeLog: * include/bits/random.h [!_GLIBCXX_USE_OLD_GENERATE_CANONICAL] (generate_canonical): Use inline namespace _V2. * include/bits/random.tcc [!_GLIBCXX_USE_OLD_GENERATE_CANONICAL] (generate_canonical): Likewise. * testsuite/26_numerics/random/pr60037-neg.cc: Remove lineno so that one dg-error matches both diagnostics. Reviewed-by: Tomasz KamiĆski <[email protected]> Diff: --- libstdc++-v3/include/bits/random.h | 6 ++++++ libstdc++-v3/include/bits/random.tcc | 2 ++ libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc | 5 +---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index ebc863e84534..5a959ed6ebec 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 c3b4776d3580..e16eb9814a55 100644 --- a/libstdc++-v3/include/bits/random.tcc +++ b/libstdc++-v3/include/bits/random.tcc @@ -3624,6 +3624,7 @@ namespace __detail constexpr bool __is_power_of_2_less_1(_Rng __range) { return ((__range + 1) & __range) == 0; }; +_GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2) /** Produce a random floating-point value in the range [0..1) * * The result of `std::generate_canonical<RealT,digits>(urng)` is a @@ -3700,6 +3701,7 @@ namespace __detail } } } +_GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) #pragma GCC diagnostic pop diff --git a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc index 13c4dc8724a4..93467eb2046a 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/pr60037-neg.cc @@ -10,7 +10,4 @@ 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 }
