[cfe-dev] Why a formalparameter object can not be treated as object reference

Richard Smith richard at metafoo.co.uk
Tue Oct 30 19:54:22 PDT 2012


On Tue, Oct 30, 2012 at 7:20 PM, 王长城 <200005275 at 163.com> wrote:
>  Hi to all:
> I have a test case which work well on VS2012,but i got an error when i
> compile it with clang++.
> the test case is:
> #include <iostream>
>
> class AA {
>  public:
>   AA(int i):ii(i){}
>   ~AA(){}
>  public:
>   int ii;
> };
>
> int foo( AA& a) {
>   return a.ii;
> }
>
> int main() {
>   AA aa(1);
>   int rec1 = foo(aa);
>   int rec2 = foo(AA(1));
>   std::cout << rec1 << '\n' << rec2 << '\n';
>   return rec1 == rec2? 0 : 1;
> }
>
> the error is:
> reference_test.cpp:18:14: error: no matching function for call to 'foo'
>   int rec2 = foo(AA(1));
>
> Is it a bug of clang or not?

It's an MSVC bug.

http://msdn.microsoft.com/en-us/library/cfbk5ddc(v=vs.80).aspx




More information about the cfe-dev mailing list