Page 1 of 1

Fucking GCC horror stories

Posted: Sun Jul 04, 2010 4:00 pm
by Arce

Code: Select all

#ifndef TEST_H
#define TEST_H
#include "qdebug.h"
class test
{
public:
    test();
    test* getInstance(){return NULL;}
    void doShit() { int x=3; qDebug()<<x;}
};

#endif // TEST_H

Code: Select all

    test a;
    test* instance=(test*)a.getInstance();
    instance->doShit();
Not only is there NO runtime error, but the log actually prints "3." Now, go make an abstract factory, very very slightly fuckup your "create" function so that it returns null, and it still "work" (on the surface). Good luck debugging...-.-;

Also, there was a point where i was doing this:

Code: Select all

bool Level::areaExists(QString) {
    for(int i=0;i<areaList.size();i++) {
        if(name.compare(areaList[i]->getName(),Qt::CaseInsensitive) == 0) {
           return true;
        }
    }
    return false;
}
I'd used a similar function in several other places, and just copy-pasted. Well, note how I accidentally didn't give the damned thing a parameter. Apparently, in GCC, that's only a warning and not an error. Couple this with the fact that GCC gives you warnings for "suggested space in 'for(;;)'" as well as other stupid shit...So, what had happened is that this function was always comparing the name of the current level (rather than the one you pass to the function) to the list of Area...Thereby almost always returning false. Since there was no error, I dismissed this quickie function as a possibility in my unexpected results in my load. A few hours later, Falco discovered this bullshit.

Granted, I should not be using the same name for the parameter and private memeber...But still. That is fucking bullshit that GCC would allow me to do that. I literally spent HOURS on gcc's fucking bullshit lack of errors, and I'm pissed.

OH, and here's another:
Add this to the above test.h:

Code: Select all

    bool doMoreShit() {/*k, what?*/}
then this in the driver:

Code: Select all

if(instance->doMoreShit()) /*what happens here?*/;
And you get a simple warning. Not error.

Re: Fucking GCC horror stories

Posted: Sun Jul 04, 2010 4:05 pm
by Arce
I guess the moral here is "fix all of your warnings." Especially on GCC.

Re: Fucking GCC horror stories

Posted: Sun Jul 04, 2010 6:20 pm
by K-Bal
Arce wrote:I guess the moral here is "fix all of your warnings." Especially on GCC.
-Wall -Weffc++ -Werror ... and prefix you member variables ;)

Re: Fucking GCC horror stories

Posted: Sun Jul 04, 2010 9:47 pm
by dejai
Since we are sharing stories about fail gcc. G++ has a bug where if you try to transform using std::lower it just will not work. Microsofts compiler can do it but g++ cannot.

So transform(str.begin(), str.end(), str.begin(), std::lower); needs to be written as std::transform( s.begin(), s.end(), s.begin(),
std::bind1st( std::mem_fun( &std::ctype<char>::tolower ),
&std::use_facet< std::ctype<char> >( loc ) ) ); at that point I just wrote my own function to turn things to lower case :)

Re: Fucking GCC horror stories

Posted: Tue Jul 06, 2010 10:43 pm
by XianForce
I remember once, I accidentally passed one too many parameters to a function. And it didn't complain at all, just tried to run it, and then it randomly crashed when it hit that function call.