c++/2810: Problems with enums (gcc 2.95 regression) boost

Peter Schmid schmid@snake.iap.physik.tu-darmstadt.de
Sat May 12 18:16:00 GMT 2001


>Number:         2810
>Category:       c++
>Synopsis:       Problems with enums (gcc 2.95 regression) boost
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sat May 12 18:16:02 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Peter Schmid
>Release:        3.0 20010503 (prerelease)
>Organization:
TU Darmstadt
>Environment:
System: Linux kiste 2.4.4 #38 Tue May 8 00:13:02 CEST 2001 i686 unknown
Architecture: i686
SuSE 7.1
glibc 2.2
GNU ld version 2.11.90.0.4 (with BFD 2.11.90.0.4)
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77,objc : (reconfigured) ../gcc/configure --enable-shared --disable-nls --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77,objc : (reconfigured) 
>Description:
The following source code tf.C, extracted from the file
libs/type_traits/tests/is_function_test.cpp from the boost repository
version 1.21.2, is rejected by gcc 3.0. gcc 2.95 accepts this code.

>How-To-Repeat:
Source code tf.C

# define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment
namespace boost{
namespace type_traits{
typedef char yes_type;
typedef double no_type;
} // namespace type_traits

// special version for gcc compiler
//
namespace detail{
   struct any_conversion
   {
      template <class T>
      any_conversion(const T&);
   };
   template <class T>
   struct checker
   {
      static boost::type_traits::no_type check(any_conversion ...);
      static boost::type_traits::yes_type check(T, int);
   };
} // namespace detail
template <class From, class To>
struct is_convertible
{
private:
   static From from;
public:
   static const bool value = sizeof( detail::checker<To>::check(from, 0) ) == sizeof(type_traits::yes_type);

   void foo(); // avoid warning about all members being private
};

template <typename T>
struct add_reference
{ typedef T& type; };
template <typename T>
struct add_reference<T&>
{ typedef T& type; };

namespace detail{
struct int_convertible
{
   int_convertible(int);
};
} // namespace detail

template <typename T> struct is_enum
{
private:
   typedef typename ::boost::add_reference<T>::type r_type;
public:
   BOOST_STATIC_CONSTANT(bool, value =
      (::boost::is_convertible<r_type, detail::int_convertible>::value));
};

} // namespace boost

unsigned failures = 0;
unsigned test_count = 0;
unsigned int expected_failures = 0;
int check_result()
{
   return (failures == expected_failures) ? 0 : failures;
}

template <bool>
struct checker
{
   static void check(bool, bool){ ++test_count; }
};

template <>
struct checker<false>
{
   static void check(bool, bool)
   {
      ++test_count;
      ++failures;
   }
};

#define value_test(v, x) checker<(v == x)>::check(v, x);

template <class T>
void is_function_test(T& foo)
{
   value_test(false, ::boost::is_enum<T>::value);
}

void foo0(){}
void foo1(int){}

int main()
{
   is_function_test(foo0);
   is_function_test(foo1);
   return check_result();
}

Compiling tf.C by gcc 3.0
g++ -v tf.C -W -Wall -save-temps
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/specs
Configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77,objc
Thread model: posix
gcc version 3.0 20010503 (prerelease)
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/cpp0 -lang-c++ -D_GNU_SOURCE -D__GNUG__=3 -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__STDC_HOSTED__=1 -W -Wall -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ tf.C tf.ii
GNU CPP version 3.0 20010503 (prerelease) (cpplib) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++-v3
 /usr/local/include/g++-v3/i686-pc-linux-gnu
 /usr/local/include
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/include
 /usr/local/i686-pc-linux-gnu/include
 /usr/include
End of search list.
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0/cc1plus -fpreprocessed tf.ii -quiet -dumpbase tf.C -W -Wall -version -o tf.s
GNU CPP version 3.0 20010503 (prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0 20010503 (prerelease) (i686-pc-linux-gnu)
	compiled by GNU C version 3.0 20010503 (prerelease).
tf.C: In instantiation of `boost::is_convertible<void (&)(), boost::detail::int_convertible>':
tf.C:53:   instantiated from `boost::is_enum<void ()()>'
tf.C:88:   instantiated from `void is_function_test(T&) [with T = void ()()]'
tf.C:96:   instantiated from here
tf.C:29: no matching function for call to 
   `boost::detail::checker<boost::detail::int_convertible>::check(void (&)(), 
   int)'
tf.C:19: candidates are: static no_type 
   boost::detail::checker<T>::check(boost::detail::any_conversion, ...) [with T 
   = boost::detail::int_convertible]
tf.C:20:                 static yes_type boost::detail::checker<T>::check(T, 
   int) [with T = boost::detail::int_convertible]
tf.C: In function `void is_function_test(T&) [with T = void ()()]':
tf.C:96:   instantiated from here
tf.C:87: warning: unused parameter `void (&foo)()'
tf.C: At global scope:
tf.C: In instantiation of `boost::is_convertible<void (&)(int), boost::detail::int_convertible>':
tf.C:53:   instantiated from `boost::is_enum<void ()(int)>'
tf.C:88:   instantiated from `void is_function_test(T&) [with T = void ()(int)]'
tf.C:97:   instantiated from here
tf.C:29: no matching function for call to 
   `boost::detail::checker<boost::detail::int_convertible>::check(void 
   (&)(int), int)'
tf.C:19: candidates are: static no_type 
   boost::detail::checker<T>::check(boost::detail::any_conversion, ...) [with T 
   = boost::detail::int_convertible]
tf.C:20:                 static yes_type boost::detail::checker<T>::check(T, 
   int) [with T = boost::detail::int_convertible]
tf.C: In function `void is_function_test(T&) [with T = void ()(int)]':
tf.C:97:   instantiated from here
tf.C:87: warning: unused parameter `void (&foo)(int)'

Compiling tf.C by gcc 2.95.2
/usr/bin/g++ -v tf.C -W -Wall 
Reading specs from /usr/lib/gcc-lib/i486-suse-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/lib/gcc-lib/i486-suse-linux/2.95.2/cpp -lang-c++ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -W -Wall -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di486 -D__i486 -D__i486__ tf.C /tmp/ccS2brQq.ii
GNU CPP version 2.95.2 19991024 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/local/include
 /usr/lib/gcc-lib/i486-suse-linux/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/lib/gcc-lib/i486-suse-linux/2.95.2/../../../../i486-suse-linux/include
End of omitted list.
 /usr/lib/gcc-lib/i486-suse-linux/2.95.2/cc1plus /tmp/ccS2brQq.ii -quiet -dumpbase tf.cc -W -Wall -version -o /tmp/ccOisxRL.s
GNU C++ version 2.95.2 19991024 (release) (i486-suse-linux) compiled by GNU C version 2.95.2 19991024 (release).
tf.C: In function `void is_function_test<void ()()>(void (&)())':
tf.C:96:   instantiated from here
tf.C:87: warning: unused parameter `void (& foo)()'
tf.C: In function `void is_function_test<void ()(int)>(void (&)(int))':
tf.C:97:   instantiated from here
tf.C:87: warning: unused parameter `void (& foo)(int)'
 /usr/i486-suse-linux/bin/as -V -Qy -o /tmp/ccHStcFV.o /tmp/ccOisxRL.s
GNU assembler version 2.10.91 (i486-suse-linux) using BFD version 2.10.0.33
 /usr/lib/gcc-lib/i486-suse-linux/2.95.2/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i486-suse-linux/2.95.2/crtbegin.o -L/usr/lib/gcc-lib/i486-suse-linux/2.95.2 -L/usr/i486-suse-linux/lib /tmp/ccHStcFV.o -lstdc++ -lm -lgcc -lc -lgcc /usr/lib/gcc-lib/i486-suse-linux/2.95.2/crtend.o /usr/lib/crtn.o

./a.out
echo $?
0

Preprocessed source code tf.ii from gcc 3.0
# 2 "tf.C"
namespace boost{
namespace type_traits{
typedef char yes_type;
typedef double no_type;
}



namespace detail{
   struct any_conversion
   {
      template <class T>
      any_conversion(const T&);
   };
   template <class T>
   struct checker
   {
      static boost::type_traits::no_type check(any_conversion ...);
      static boost::type_traits::yes_type check(T, int);
   };
}
template <class From, class To>
struct is_convertible
{
private:
   static From from;
public:
   static const bool value = sizeof( detail::checker<To>::check(from, 0) ) == sizeof(type_traits::yes_type);

   void foo();
};

template <typename T>
struct add_reference
{ typedef T& type; };
template <typename T>
struct add_reference<T&>
{ typedef T& type; };

namespace detail{
struct int_convertible
{
   int_convertible(int);
};
}

template <typename T> struct is_enum
{
private:
   typedef typename ::boost::add_reference<T>::type r_type;
public:
   static const bool value = (::boost::is_convertible<r_type, detail::int_convertible>::value);

};

}

unsigned failures = 0;
unsigned test_count = 0;
unsigned int expected_failures = 0;
int check_result()
{
   return (failures == expected_failures) ? 0 : failures;
}

template <bool>
struct checker
{
   static void check(bool, bool){ ++test_count; }
};

template <>
struct checker<false>
{
   static void check(bool, bool)
   {
      ++test_count;
      ++failures;
   }
};



template <class T>
void is_function_test(T& foo)
{
   checker<(false == ::boost::is_enum<T>::value)>::check(false, ::boost::is_enum<T>::value);;
}

void foo0(){}
void foo1(int){}

int main()
{
   is_function_test(foo0);
   is_function_test(foo1);
   return check_result();
}

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list