Topic: Will r-value be treated as const for function template deduction


Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/04/15
Raw View
Michael Podolsky <michael_podolsky@my-dejanews.com> writes:

> So my question is what ANSI C++ says?

As far as I understand ISO C++ (sic :-), 14.8.2.1/2 is the first step
here:

>> If P is a reference type, the type referred to by P is used for
>> type deduction.

So we try to deduce the type for T, and get T=int. Then we instantiate
the template with <int>, and perform overload resolution. We try to
initialize a non-const reference with an rvalue, which is an error
(isn't it?). So the whole thing is ill-formed.

Regards,
Martin
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Michael Podolsky <michael_podolsky@my-dejanews.com>
Date: 1999/04/14
Raw View
Hi all

I tried to undestand what C++ standard says about the subject,
yet without success.

Particularly:

template <class T>
void Check(T&t)
{
 extern T undefined; // just small trick
        T access=undefined; //  to understand what is T
}

void Use()
{
    int i;
    const int ci;
    Check(i);  //  Check(int &) is called - OK
    Check(ci); //  Check(int const&) is called - OK
    Check(1);  // What ANSI C++ says about it?
};

I tried to check the issue with Visual 6.0 - in the last case
it calls Check(int const&), yet when I tried more complex stuff -
 Check( i + i ) - it failed compilation trying to call Check(int &) and
obviously failing on binding non-const reference to r-value.

So my question is what ANSI C++ says?

Thanks.

Michael


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]