This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug report


The attached file doesn't compile in gcc 2.95.2. I believe it to be
correct (the code, that is). I'm using Red Hat 6.0 on an i686. I'm not
passing any options to the compiler.

The conversion template is the work of Andrei Alexandrescu
<andrewalex@hotmail.com>.
 
-- 
Braden N. McDaniel
braden@endoframe.com
<URL:http://www.endoframe.com>
#include <iostream.h>

template <class From, class To>
class conversion
{
 typedef char (&no)[1];
 typedef char (&yes)[2];
 static no check(...);
 static yes check(To);
public:
 void foo();
 static const bool exists = sizeof(check(From())) == sizeof(yes);
 static const bool exists_twoway = exists &&
  conversion<To, From>::exists;
 static const bool same_type = false;
};

template <class From>
class conversion<From, void>
{
public:
 static const bool exists = false;
 static const bool exists_twoway = false;
 static const bool same_type = false;
};

template <class To>
class conversion<void, To>
{
public:
 static const bool exists = false;
 static const bool exists_twoway = false;
 static const bool same_type = false;
};

template <>
class conversion<void, void>
{
public:
 static const bool exists = true;
 static const bool exists_twoway = true;
 static const bool same_type = true;
};

template <class T>
class conversion<T, T>
{
public:
 static const bool exists = true;
 static const bool exists_twoway = true;
 static const bool same_type = true;
};

struct base {
  virtual ~base() {}
};

struct derived : public base {};

int main() {
  if (conversion<const derived *, const base *>::exists) {
    cout << "Bing!" << endl;
  }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]