libstdc++: Fix tr1::variate_generator::engine_value_type
authorJonathan Wakely <jwakely@redhat.com>
Fri, 16 Sep 2022 14:40:06 +0000 (15:40 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 16 Sep 2022 14:54:42 +0000 (15:54 +0100)
commitb6adc6255f527edd50c08c4aacb4ee21df1c349c
treea8313e0e492b227698294727a138e8ddd46ed705
parent5ad435f2a0d29486c917025dfa239b9b88c35a09
libstdc++: Fix tr1::variate_generator::engine_value_type

The tr1/5_numerical_facilities/random/variate_generator/37986.cc test
fails for strict -std=c++98 mode because _Adaptor(const _Engine&) is
ill-formed in C++98 when _Engine is a reference type.

Rather than attempt to make the _Adaptor handle references and pointers,
just strip references and pointers from the _Engine type before we adapt
it. That removes the need for the _Adaptor<_Engine*> partial
specialization and avoids the reference-to-reference problem for c++98
mode.

While looking into this I noticed that the TR1 spec requires the
variate_generator<E,D>::engine_value_type to be the underlying engine
type, whereas we make it the _Adaptor<E> type that wraps the engine.

libstdc++-v3/ChangeLog:

* include/tr1/random.h (__detail::_Adaptor::_BEngine): Remove.
(__detail::_Adaptor::_M_g): Make public.
(__detail::_Adaptor<_Engine*, _Dist>): Remove partial
specialization.
(variate_generate::_Value): New helper to simplify handling of
_Engine* and _Engine& template arguments.
(variate_generate::engine_value_type): Define to underlying
engine type, not adapted type.
(variate_generate::engine()): Return underlying engine instead
of adaptor.
* testsuite/tr1/5_numerical_facilities/random/variate_generator/37986.cc:
Fix comment.
* testsuite/tr1/5_numerical_facilities/random/variate_generator/requirements/typedefs.cc:
Check member typedefs have the correct types.
libstdc++-v3/include/tr1/random.h
libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/variate_generator/37986.cc
libstdc++-v3/testsuite/tr1/5_numerical_facilities/random/variate_generator/requirements/typedefs.cc