// The optimization level should not prevent a conforming program // to compile and link correctly. This program shows that this // is not the case for GCC 4.1.1.
template <typename T> struct c { static const int a = 3; static const int b = 4; }; // If the following `#if 0' is turned into `#if 1', then the program // links only with -O2 and higher optimization levels. #if 0 int not_ok() { return c<int>().a; } int not_ok(bool b) { return b ? c<int>::a : c<int>::b; } #endif // The following functions should be completely equivalent to the // above ones, but these do not cause any linking problem, whatever // the optimization level is. int ok() { // How is this different from `return c<int>().a'? return c<int>::a; } int ok(bool b) { // How is this different from `return b ? c<int>::a : c<int>::b'? if (b) return c<int>::a; else return c<int>::b; } int main(int, char**) { } -- Summary: Program links only at -O2 or above Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bagnara at cs dot unipr dot it GCC host triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29803