[Bug c++/34023] Wrong using of user-defined conversion operator for converting rvalue to reference on constant.
sergey dot gcc at comrades dot id dot au
gcc-bugzilla@gcc.gnu.org
Thu Nov 29 00:04:00 GMT 2007
------- Comment #5 from sergey dot gcc at comrades dot id dot au 2007-11-29 00:04 -------
(In reply to comment #3)
> // Workaround:
> class a
> {
> public:
> template<class T>
> operator T &() const
> throw(typename ::boost::disable_if<
> ::boost::is_same<T, ref_t const> >::type *)
> {
> static int f;
> return f;
> }
> };
>
> int main()
> {
> a const &aa = a(); // line # 27
> int &i = aa;
> }
>
This workaround should not work, according to the standard
14.8.2.2
- All references in the function type of the function template to the
corresponding template parameters are replaced by the specified template
argument values. If a substitution in a template parameter or in the function
type of the function template results in an invalid type, type deduction fails.
[Note: The equivalent substitution in exception specifications is done only
when the function is instantiated, at which point a program is ill-formed if
the substitution results in an invalid type.] Type deduction may fail for the
following reasons:
However, it works on GCC. It is another bug in GCC.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34023
More information about the Gcc-bugs
mailing list