www.digitalmars.com         C & C++   DMDScript  

c++ - maybe a bug report

reply "Jim Jennings" <jwjenn mindspring.com> writes:
I believe there may be a problem here.

using namespace std;
class CBox
{
   public:
      CBox(double lv = 1.0, double bv = 1.0, double hv = 1.0)
                : m_Height(hv), m_Length(lv), m_Breadth(bv)
      { }
   private:
      double m_Length;
      double m_Breadth;
      double m_Height;
};
int main()
{
    CBox aBox = 2;                               //OK
    CBox bBox = aBox;                        //OK
    CBox cBox = 2 < 3 ? aBox : 3;      // ERROR
}

 C:\dm\bin\sc -Ae -C -WA -S -5 -a8 test2.cpp -I\dm\stlport\stlport
    CBox cBox = 2 < 3 ? aBox : 3; //Burp
                                ^
test2.cpp(21) : Error: illegal operand types
Had: CBox
and: int
--- errorlevel 1
Apr 05 2003
next sibling parent reply roland <--rv ronetech.com> writes:
Jim Jennings wrote:

 I believe there may be a problem here.
 
. .
     CBox cBox = 2 < 3 ? aBox : 3;      // ERROR
. . I'm not a C syntax specialist but it seems to me some parentesis are missing here. I personaly would have written this that way: CBox cBox = (2 < 3) ? aBox : 3;
Apr 05 2003
parent "Jim Jennings" <jwjenn mindspring.com> writes:
"roland" <--rv ronetech.com> wrote in message
news:3E8EF4C8.3050203 ronetech.com...
 Jim Jennings wrote:

 I believe there may be a problem here.
     CBox cBox = 2 < 3 ? aBox : 3;      // ERROR
I'm not a C syntax specialist but it seems to me some parentesis are missing here. I personaly would have written this that way: CBox cBox = (2 < 3) ? aBox : 3;
roland, < has a higher operator precedence than ?: Here is the result with parentheses: C:\dm\bin\sc -Ae -C -WA -S -5 -a8 test2.cpp -I\dm\stlport\stlport CBox cBox = (2 < 3) ? aBox : 3; ^ test2.cpp(24) : Error: illegal operand types Had: CBox and: int --- errorlevel 1
Apr 05 2003
prev sibling parent reply "Matthew Wilson" <dmd synesis.com.au> writes:
Certainly is. The 2 < 3 should be parsed correctly, and the 2nd 3 should be
implicitly converted to a CBox. CodeWarrior compiles this without issue.

"Jim Jennings" <jwjenn mindspring.com> wrote in message
news:b6mq4c$12as$1 digitaldaemon.com...
 I believe there may be a problem here.

 using namespace std;
 class CBox
 {
    public:
       CBox(double lv = 1.0, double bv = 1.0, double hv = 1.0)
                 : m_Height(hv), m_Length(lv), m_Breadth(bv)
       { }
    private:
       double m_Length;
       double m_Breadth;
       double m_Height;
 };
 int main()
 {
     CBox aBox = 2;                               //OK
     CBox bBox = aBox;                        //OK
     CBox cBox = 2 < 3 ? aBox : 3;      // ERROR
 }

  C:\dm\bin\sc -Ae -C -WA -S -5 -a8 test2.cpp -I\dm\stlport\stlport
     CBox cBox = 2 < 3 ? aBox : 3; //Burp
                                 ^
 test2.cpp(21) : Error: illegal operand types
 Had: CBox
 and: int
 --- errorlevel 1
Apr 05 2003
next sibling parent reply "Jim Jennings" <jwjenn mindspring.com> writes:
"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:b6nl2n$1m3e$1 digitaldaemon.com...
 Certainly is. The 2 < 3 should be parsed correctly, and the 2nd 3 should
be
 implicitly converted to a CBox. CodeWarrior compiles this without issue.
I checked it out with g++ and Borland, and they both compiled OK. I try to do that with all of the anomalies first. I find that often it is me and not the compiler. BTW, I thought I had deleted the "Burp" but forgot that I had recompiled with the comment still there. Thanks for the confirmation. Jim J.
 "Jim Jennings" <jwjenn mindspring.com> wrote in message
 news:b6mq4c$12as$1 digitaldaemon.com...
 I believe there may be a problem here.

 using namespace std;
 class CBox
 {
    public:
       CBox(double lv = 1.0, double bv = 1.0, double hv = 1.0)
                 : m_Height(hv), m_Length(lv), m_Breadth(bv)
       { }
    private:
       double m_Length;
       double m_Breadth;
       double m_Height;
 };
 int main()
 {
     CBox aBox = 2;                               //OK
     CBox bBox = aBox;                        //OK
     CBox cBox = 2 < 3 ? aBox : 3;      // ERROR
 }

  C:\dm\bin\sc -Ae -C -WA -S -5 -a8 test2.cpp -I\dm\stlport\stlport
     CBox cBox = 2 < 3 ? aBox : 3; //Burp
                                 ^
 test2.cpp(21) : Error: illegal operand types
 Had: CBox
 and: int
 --- errorlevel 1
Apr 05 2003
parent "Matthew Wilson" <dmd synesis.com.au> writes:
Pleasure

"Jim Jennings" <jwjenn mindspring.com> wrote in message
news:b6nusl$1t62$1 digitaldaemon.com...
 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:b6nl2n$1m3e$1 digitaldaemon.com...
 Certainly is. The 2 < 3 should be parsed correctly, and the 2nd 3 should
be
 implicitly converted to a CBox. CodeWarrior compiles this without issue.
I checked it out with g++ and Borland, and they both compiled OK. I try to do that with all of the anomalies first. I find that often it is me and
not
 the compiler.
 BTW, I thought I had deleted the "Burp" but forgot that I had recompiled
 with the comment still there.
 Thanks for the confirmation.
 Jim J.
 "Jim Jennings" <jwjenn mindspring.com> wrote in message
 news:b6mq4c$12as$1 digitaldaemon.com...
 I believe there may be a problem here.

 using namespace std;
 class CBox
 {
    public:
       CBox(double lv = 1.0, double bv = 1.0, double hv = 1.0)
                 : m_Height(hv), m_Length(lv), m_Breadth(bv)
       { }
    private:
       double m_Length;
       double m_Breadth;
       double m_Height;
 };
 int main()
 {
     CBox aBox = 2;                               //OK
     CBox bBox = aBox;                        //OK
     CBox cBox = 2 < 3 ? aBox : 3;      // ERROR
 }

  C:\dm\bin\sc -Ae -C -WA -S -5 -a8 test2.cpp -I\dm\stlport\stlport
     CBox cBox = 2 < 3 ? aBox : 3; //Burp
                                 ^
 test2.cpp(21) : Error: illegal operand types
 Had: CBox
 and: int
 --- errorlevel 1
Apr 05 2003
prev sibling parent Richard Grant <fractal clark.net> writes:
In article <b6nl2n$1m3e$1 digitaldaemon.com>, Matthew Wilson says...
Certainly is. The 2 < 3 should be parsed correctly, and the 2nd 3 should be
implicitly converted to a CBox. CodeWarrior compiles this without issue.
Other than another compiler being able to compile this, the form of the statement violates the rules expressed in 5.16.3 for conversion of expressions in the conditional operator. You can fixup the code like: CBox cBox = (2 < 3) ? aBox : CBox(3); Richard
Apr 10 2003