Reset branch to trunk.
[official-gcc.git] / trunk / gcc / testsuite / g++.dg / opt / pr19650.C
blob96cbd8ad80ddc1132d1b13193a4937ff4a90f8ac
1 // { dg-options "-O1 -w -fpermissive" }
2 // { dg-do "run" }
3 // Tests the fold bug described in PR 19650.
4 #include <stdio.h>
5 #include <stdlib.h>
6 #define test(a) ((a) ? 1 : 0)
8 typedef int (*arg_cmp_func)();
10 class Item_func 
12 public:
13     enum Functype { UNKNOWN_FUNC, EQ_FUNC, EQUAL_FUNC };
14     virtual enum Functype functype() const { return UNKNOWN_FUNC; }
17 class Item_bool_func2 : public Item_func
19 public:
20     virtual enum Functype functype() const { return EQUAL_FUNC; }
23 class Arg_comparator 
25 public:
26     Item_bool_func2 *owner;
27     arg_cmp_func func;
28     static arg_cmp_func comparator_matrix[4][2];
30     int Arg_comparator::set_compare_func(Item_bool_func2 *item, int type)
31     {
32         owner = item;
34         /****************** problematic line is here ************************/
36         func = comparator_matrix[type][test(owner->functype() == Item_func::EQUAL_FUNC)];
37         return 0;
38     }
41 int compare_string() { return 0; }
42 int compare_e_string() { return 0; }
43 int compare_real() { return 0; }
44 int compare_e_real() { return 0; }
45 int compare_int_signed() { return 0; }
46 int compare_e_int() { return 0; }
47 int compare_row() { return 0; }
48 int compare_e_row() { return 0; }
50 arg_cmp_func Arg_comparator::comparator_matrix[4][2] =
51     {{&compare_string,     &compare_e_string},
52      {&compare_real,       &compare_e_real},
53      {&compare_int_signed, &compare_e_int},
54      {&compare_row,        &compare_e_row}};
56 void myfunc (const char*p, arg_cmp_func f1, arg_cmp_func f2) __attribute__((noinline));
57 void myfunc (const char*p, arg_cmp_func f1, arg_cmp_func f2)
59     if (f1!=f2)
60       abort ();
63 int main()
65     Arg_comparator cmp;
66     Item_bool_func2 equal_func;
68     cmp.set_compare_func(&equal_func, 0);
69     myfunc("cmp.func is %p (expected %p)\n", cmp.func, &compare_e_string);