c++ - maybe a bug report
- Jim Jennings (26/26) Apr 05 2003 I believe there may be a problem here.
- roland (8/11) Apr 05 2003 .
- Jim Jennings (12/19) Apr 05 2003 roland,
- Matthew Wilson (4/30) Apr 05 2003 Certainly is. The 2 < 3 should be parsed correctly, and the 2nd 3 should...
- Jim Jennings (10/44) Apr 05 2003 be
- Matthew Wilson (4/51) Apr 05 2003 Pleasure
- Richard Grant (7/9) Apr 10 2003 Other than another compiler being able to compile this, the form of the
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
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
"roland" <--rv ronetech.com> wrote in message news:3E8EF4C8.3050203 ronetech.com...Jim Jennings wrote: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 1I believe there may be a problem here.CBox cBox = 2 < 3 ? aBox : 3; // ERRORI'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
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
"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 shouldbeimplicitly 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
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...notCertainly is. The 2 < 3 should be parsed correctly, and the 2nd 3 shouldbeimplicitly 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 andthe 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
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