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: unassig...@gcc.gnu.org

        ReportedBy: daniel.krueg...@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).

Reply via email to