Xref: utzoo comp.os.msdos.programmer:1595 comp.lang.c++:10059 Path: utzoo!attcan!uunet!midway!linac!uwm.edu!wuarchive!mit-eddie!uw-beaver!zephyr.ens.tek.com!tektronix!reed!minar From: minar@reed.bitnet (Nelson Minar,L08,x640,7776519) Newsgroups: comp.os.msdos.programmer,comp.lang.c++ Subject: Possible bug in Turbo C++ dealing with inline functions returning Summary: should this work? Message-ID: <15588@reed.UUCP> Date: 21 Oct 90 22:38:09 GMT Sender: news@reed.UUCP Reply-To: minar@reed.bitnet (Nelson Minar) Followup-To: comp.os.msdos.programmer Organization: Reed College, Portland, OR Lines: 75 Sender: I have encountered something extemely nondesirable about how Turbo C++ 1.0 handles inline functions returning class instances. It seems to get very confused about them, and won't compile conditionals complaining about required destructors (explicitly declaring a destructor is no help). g++ 1.37.1 has no trouble at all compiling this same piece of code. Here is the error output of tcc: inlines.cpp: Error inlines.cpp 13: Destructor for Foo required in conditional expression in function test(int) Error inlines.cpp 13: Destructor for Foo required in conditional expression in function test(int) and here is the program: // This compiles under g++ 1.37.1, but will not compile in Turbo C++ 1.0 // with the compilation options '-y -v -vi- -N' or '-y -v -vi -N' #include class Foo { public: Foo() {} // plain constructor Foo(int x) { value = x; } // constructor taking an int operator int() { return value; } // conversion int value; }; inline Foo test (int input) { return input == 1 ? Foo (4) : Foo (3); // line 13 - return a Foo } // depending on input void main() { Foo testVal; testVal = test(0); // testVal should be Foo(3) printf ("%d", int(testVal)); // g++ gives expected answer } Even weirder, this program will compile fine without inlining functions ('-vi-') but will give the same "Destructor required" errors when compiled with inlining functions ('-vi'), IF the conditional expression return input == 1 ? Foo (4) : Foo (3); is turned into the equivalent if-then construct: if (input == 1) return Foo(4); else return Foo(3); Not very useful, as I still can't inline the function. it will also compile ok if there are not multiple return points in the inlined function, say return Foo(input); Is this a bug, is it me being stupid about trying to learn C++, or just another 'interpretation' of the C++ 2.0 standard like Borland's for loop thing is? Its excessively annoying, as the function I am trying to inline really needs to be inlined. I think I'll have to switch to a macro, or some ugly function-with-side-effect answer. I haven't tried to get to tech support yet, partially because their tech support is a real pain, and partially because I do not know how to get Borland a copy of the source code. Is there ANY address on the Net that will get to a Borland tech? I don't care if I have to wait for a snail- mail reply... __ \/ minar@reed.bitnet You know in your heart its flat.