refcast ambiguity "((<typename> &) <expression>)"

refcast ambiguity "((<typename> &) <expression>)"

Post by Jacob Butch » Fri, 08 Oct 1993 06:13:57



With the following declarations:

                class to {
                };

                class from {
                  public:
                    int before;
                    to aTo;

                    operator
                        to &()
                            { return (this->aTo); }
                };

most compilers (for example, Sun's) compile these two statements identically:

                to &t = f;
                to &t = ((to &) (f));

However, IBM's xlC compiler for AIX on an IBM RT compiles them differently.
Specifically, that compiler invokes the user-defined conversion for the
first statement, but does *not* invoke that conversion for the second
statement.  When I reported this discrepancy to IBM, they pointed out that
the ARM, section 5.4, page 69, line 9 states that

        ``Constructors or conversion functions are not called as
        the result of a cast to a reference.''

which certainly supports their implementation.  However, their implementation
violates what I (perhaps naively) assume to be an invariant of the language,
which is that if it is legal to assign an expression of type F to a variable
of type T, then it is legal to *cast* an expression of type F to type T, and
the operations are identical.  (Actually, C++ is sufficiently complex that
I'm not *too* attached to that invariant in general... I just want to say
that as a user I am *very* suprised by this discrepancy, and I think it is
wrong.)  So, is IBM mis-interpreting the ARM, or is theirs indeed a legitemate
interpretation of a deliberate ambiguity in the language?

                                Jacob Butcher

 
 
 

refcast ambiguity "((<typename> &) <expression>)"

Post by Scott Turn » Thu, 14 Oct 1993 01:28:54



> most compilers (for example, Sun's) compile these two statements identically:

>            to &t = f;
>            to &t = ((to &) (f));

> However, IBM's xlC compiler for AIX on an IBM RT compiles them differently.
> However, their implementation
> violates what I (perhaps naively) assume to be an invariant of the language,
> which is that if it is legal to assign an expression of type F to a variable
> of type T, then it is legal to *cast* an expression of type F to type T, and
> the operations are identical.

That would be nice as an invariant, but C++ explicit casts break it.
For example,

        void foo(float x) {
                const int &r1 = x;         // Refer to a temporary int object.
                const int &r2 = (const int &)x;  // Reinterpret the bits of x.
        }
--
Prescott K. Turner, Jr.
Liant Software Corp. (developers of LPI languages)
959 Concord St., Framingham, MA 01701 USA    (508) 872-8700


 
 
 

refcast ambiguity "((<typename> &) <expression>)"

Post by Scott Turn » Wed, 13 Oct 1993 22:48:38



> most compilers (for example, Sun's) compile these two statements identically:

>            to &t = f;
>            to &t = ((to &) (f));

> However, IBM's xlC compiler for AIX on an IBM RT compiles them differently.
> However, their implementation
> violates what I (perhaps naively) assume to be an invariant of the language,
> which is that if it is legal to assign an expression of type F to a variable
> of type T, then it is legal to *cast* an expression of type F to type T, and
> the operations are identical.  

That would be a nice invariant to have, but C++ reference casts break it.
For example,
        void foo(float x) {
                const int &r1 = x;  // refer to a temporary int object
                const int &r2 = (const int &)x;  // reinterpret the bits of x
        }
--
Prescott K. Turner, Jr.
Liant Software Corp. (developers of LPI languages)
959 Concord St., Framingham, MA 01701 USA    (508) 872-8700

 
 
 

1. cout << "(" << ")";

Using Borland Turbo C++ 4.5 on Intel/Win98 in console mode.

 out1 << "    (" << indexLoc << ") " << "X'" < hexWord << "',";

gives errors:
Warning EEFCC.CPP 117: Ambiguous operators need parentheses in function
main(int,char * *)
Warning EEFCC.CPP 117: Ambiguous operators need parentheses in function
main(int,char * *)
Error EEFCC.CPP 117: Illegal use of pointer in function main(int,char * *)

I know that this is dumb, but how do I print out the '(' and ')' in a literal?

--
"I'm not lost, I just don't know where I am!"
In the interest of anti-spam, I have added numerics to my email address

Ray

2. LAUG meeting @ 7.30pm on 14.01.03

3. HELP >>>>>>>>>>>>> WINAPI <<<<<<<<<<<<<<<<<

4. Ram Card

5. <<<<<<Programmers Needed>>>>>>>

6. saving as eps?

7. <<>><><><><><><><><><><>

8. G.722 (SB-ADPCM)

9. >>>>>>>>> PROBLEM WITH MSICPB.EXE <<<<<<<<<<<<<<<<<

10. <><><> www.FotoCD.net <><><>

11. static_cast<ofstream>("Hello world.txt");

12. ************************<<<<<<LOTUS CORP.SUCKS>>>>>*****************