This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34023] Wrong using of user-defined conversion operator for converting rvalue to reference on constant.
- From: "sergey dot gcc at comrades dot id dot au" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Nov 2007 00:04:00 -0000
- Subject: [Bug c++/34023] Wrong using of user-defined conversion operator for converting rvalue to reference on constant.
- References: <bug-34023-12808@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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