[Bug c++/56208] New: sizeof sfinae fails to work

daniel.kruegler at googlemail dot com gcc-bugzilla@gcc.gnu.org
Mon Feb 4 19:38:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56208

             Bug #: 56208
           Summary: sizeof sfinae fails to work
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: daniel.kruegler@googlemail.com


The following program becomes rejected when compiled with gcc 4.8.0 trunk using
the flags:

-Wall -pedantic

(with or without -std=c++11)

//--------------------------------
struct ostream {
  ostream& operator<<(int);
};

struct sfinae_base {

  typedef char one;
  typedef char (&two)[2];

  template<class T>
  static T make();

  template<unsigned> struct ok { typedef int type; };

  template<class U, class T>
  static one test(typename ok<sizeof(
    make<U>() << make<T>()
  )>::type);

  template<class, class>
  static two test(...);

};

template<class T>
struct is_printable : private sfinae_base
{
  enum { value = sizeof(test<ostream&, T>(0)) == sizeof(one) };
};

typedef int ok[is_printable<int>::value ? 1 : -1];

int main() {}
//--------------------------------

"Compilation finished with errors:
source.cpp:31:49: error: size of array 'ok' is negative
typedef int ok[is_printable<int>::value ? 1 : -1];
^"

It worked with gcc 4.7.2 (also with Clang 3.2 or Intel-13), so this looks like
a regression to me. Operator<< is not the only one, I also noted problems with
other operators (such as binary plus).



More information about the Gcc-bugs mailing list