C++ bug: tree based representation of "switch"?

Gerald Pfeifer pfeifer@dbai.tuwien.ac.at
Mon Sep 18 08:26:00 GMT 2000


Once GNATS is fully operational again I'll also submit this testcase
there, but here, finally, a small example showing two bugs (probably)
introduced by the switch to the tree based representation of "switch".

  gomeisa[279]:~/tmp% gccvs -O2 x.cc
  x.cc: In function `void foo (const TC<IDENT> &)':
  x.cc:13: warning: unreachable code at beginning of switch statement
  x.cc:48: Internal error: Segmentation Fault.
     Please submit a full bug report.
     See <URL: http://www.gnu.org/software/gcc/bugs.html > for instructions.

The warning is completely incorrect, and if you remove the string ": "
from the print statement in foo(), both the warning and the crash will
go away.

Seen on sparc-sun-solaris2.6. (Originally also on i386-unknown-freebsd4.1,
but the reduced testcase does not trigger there any longer, though I'm
still getting similiar behavior for the full code.)


Mark, finally this is the bug that actually triggered those other three
reports for bugs I came across while trying to generate a testcase. :-}

Gerald

-------- cut --------
#include <iostream>
#include <pair.h>

struct IDENT
    {
    enum TYPE { Variable, Constant } type;

    ostream& printTo(ostream& out) const
	{
	switch (type)
	    {
	    case Variable:
		out << '_';
		break;
	    default:
		break;
	    }
	return out;
	}
    };


template <class T>
struct TC
    {
    typedef pair<IDENT, IDENT> WEIGHTS;
    WEIGHTS weights;

    const WEIGHTS& getWeights() const
        {
	return weights;
	}
    };

template <class T>
inline ostream& operator<< (ostream& out, const TC<T> &wconstr)
    {
    wconstr.getWeights().first.printTo(out);
    return out;
    }

void foo(const TC<IDENT> &c)
    {
    cerr << c 
         << ": " // This line is crucial!
         << c
         << endl;
    }




More information about the Gcc-bugs mailing list