Qball's Weblog

Natty G++ bug. Always fun

Tags Grind My Gears 

Bug report: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48822

Code to trigger the bug:

?View Code CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio .h>
#include <list>
#include <ostream>
#include <vector>
#include <climits>
 
// Greatest common divisor
template <class T>
T gcd(T a, T b)
{
    T t;
 
    while (b != )
    {
        t = b;
        b = a % b;
        a = t;
    }
 
    return a;
}
class CFraction
{
public:
    // Constructor
    CFraction(const int num = , const int den = 1) 
    { 
        this->num = num; 
        this->den = den; 
        fraction = true; 
        if(den != ) val = (double)(num) / (double)(den);
        else val = 0.0;
    };
    // Destructor
    ~CFraction() {};
 
    // Fraction contains a real fraction?
    bool isFraction() const { return fraction; };
 
    // Fractional parts
    long long int numerator() const { return num; };
    long long int denominator() const { return den; };
 
    // Real value
    double value() const { return val; };
 
    // Lowest term
    CFraction lowestTerm() const
    {
        CFraction tmp;
        long long int g = gcd(num, den);
        tmp.num = num / g;
        tmp.den = den / g;
        tmp.val = ((double)tmp.num) / (double) tmp.den;
        return tmp;
    }
 
    bool operator==(const CFraction &rhs) const
    {
        if (!isFraction() || !rhs.isFraction())
            return value() == rhs.value();
 
        if (den ==  && rhs.den ==  && num == rhs.num)
            return true;
 
        if (den ==  || rhs.den == )
            return false;
 
        CFraction r = rhs.lowestTerm();
        CFraction l = lowestTerm();
 
        if (r.den == l.den && r.num == l.num)
            return true;
 
        return false;
    }
 
private:
    bool fraction;
    double val;
    long long int num;
    long long int den;
};
 
 
int main(void){
	CFraction a(2,1);
 
	if(a == CFraction(,))
	{
		printf("Whoopie\n");	
	}
    return ;
}
</class></climits></vector></ostream></list></stdio>

(stupid highlighting is adding closing tags on the last line, ignore them).

If you compile this with gcc 4.5.2 (64 bit?)

?View Code BASH
1
g++ -O2 test.cc