Topic: reference binding and rvalues


Author: "Ruslan Abdikeev" <ruslan_abdikeevRemoveIt@hotmail.com>
Date: Tue, 10 Apr 2001 00:38:35 GMT
Raw View
"Andrea Ferro" <AndreaF@UrkaDVD.it> wrote in message
news:9aq9lo$jl9$1@serv1.iunet.it...
> According to my understanding of the standard a non constant reference
should
> not bind to an rvalue.

Right.

> This code, however, compiles with no diagnostic on VC6 &
> 7 and someone told me the same is for BCPP and at least one unix open
source
> compiler (dunno which).

Not right.
Code you have posted does NOT successfully compile on VC6 and VC7.
Binding r-values to non-const references is an extension to language in
VC6/7.
Just set 4th warning level or disable language extensions in VC6.

>   struct X {};
>   X f() { return X(); }
>   int main()
>   {
>     X& x1=X(); // invalid IMO, invalid in VC6, VC7
>     X& x2=f(); // invalid IMO, invalid in VC6, VC7
>   }


Sincerely,

Ruslan Abdikeev
Brainbench MVP for Visual C++
http://www.brainbench.com




---
[ 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://www.research.att.com/~austern/csc/faq.html                ]





Author: "Andrea Ferro" <AndreaF@UrkaDVD.it>
Date: Tue, 10 Apr 2001 19:49:28 GMT
Raw View
"Ruslan Abdikeev" <ruslan_abdikeevRemoveIt@hotmail.com> wrote in message
news:9at74m$beq$1@news.wplus.spb.ru...
> "Andrea Ferro" <AndreaF@UrkaDVD.it> wrote in message
> news:9aq9lo$jl9$1@serv1.iunet.it...
...
> > This code, however, compiles with no diagnostic on VC6 &
> > 7 and someone told me the same is for BCPP and at least one unix open
> source
> > compiler (dunno which).
>
> Not right.
> Code you have posted does NOT successfully compile on VC6 and VC7.
> Binding r-values to non-const references is an extension to language in
> VC6/7.
> Just set 4th warning level or disable language extensions in VC6.

Sorry for asking. What turns me up is that I believed I had VC7 settings to
conforming and I actually did not! Too many switches there!

--

Andrea Ferro

---------
Brainbench C++ Master. Scored higher than 97% of previous takers
Scores: Overall 4.46, Conceptual 5.0, Problem-Solving 5.0
More info http://www.brainbench.com/transcript.jsp?pid=2522556



---
[ 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://www.research.att.com/~austern/csc/faq.html                ]





Author: "Andrea Ferro" <AndreaF@UrkaDVD.it>
Date: Mon, 9 Apr 2001 15:29:57 CST
Raw View
According to my understanding of the standard a non constant reference should
not bind to an rvalue. This code, however, compiles with no diagnostic on VC6 &
7 and someone told me the same is for BCPP and at least one unix open source
compiler (dunno which).

Is this compilers noncomformancy or did I miss something in the standard?

  struct X {
  };

  X f() { return X(); }

  int main()
  {
    X& x1=X(); // invalid IMO, but compiles
    X& x2=f(); // invalid IMO, but compiles

    const X& cx1=X(); // Ok
    const X& cx2=f(); // Ok
  }

--

Andrea Ferro

---------
Brainbench C++ Master. Scored higher than 97% of previous takers
Scores: Overall 4.46, Conceptual 5.0, Problem-Solving 5.0
More info http://www.brainbench.com/transcript.jsp?pid=2522556



---
[ 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://www.research.att.com/~austern/csc/faq.html                ]





Author: "Michael Kochetkov" <Michael.Kochetkov@trustworks.commmm>
Date: Mon, 9 Apr 2001 22:12:07 GMT
Raw View
"Andrea Ferro" <AndreaF@UrkaDVD.it> wrote in message
news:9aq9lo$jl9$1@serv1.iunet.it...
> According to my understanding of the standard a non constant reference
should
> not bind to an rvalue. This code, however, compiles with no diagnostic on
VC6 &
> 7 and someone told me the same is for BCPP and at least one unix open
source
> compiler (dunno which).
>
> Is this compilers noncomformancy or did I miss something in the standard?
This question is number one at the comp.lang.c++ for the last year. Please,
have a look at -Za switch in VC help.

>
>   struct X {
>   };
>
>   X f() { return X(); }
>
>   int main()
>   {
>     X& x1=X(); // invalid IMO, but compiles
>     X& x2=f(); // invalid IMO, but compiles
>
>     const X& cx1=X(); // Ok
>     const X& cx2=f(); // Ok
>   }

With regards,
Michael Kochetkov.



---
[ 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://www.research.att.com/~austern/csc/faq.html                ]