g++ fails to compile a program that has a template parameter with a boolean expression involving a templated static constant
Issue
-
g++ fails to compile a program that has a template parameter with a boolean expression involving a templated static constant
-
This problem is seen when the boost library is used in the following manner:
#include <boost/mpl/if.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/vector.hpp>template < class FieldTypes, class BaseType >
struct PlainTraits
{
static const std::size_t fields_num = boost::mpl::size< FieldTypes >::value;
static const std::size_t total_size = fields_num * sizeof( BaseType );//enum { can_be_viewed_as_plain = total_size % sizeof( BaseType ) == 0 };
BOOST_MPL_ASSERT( total_size % sizeof( BaseType ) == 0 );
};PlainTraits< boost::mpl::vector<int,int>, int > x;
-
Uncommenting the line in bold above allows the code to compile.
-
The compilation error for the above code:
test.cpp: In instantiation of 'PlainTraits<boost::mpl::vector<int, int, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, int>':
test.cpp:16: instantiated from here
test.cpp:13: error: '((((long unsigned int)PlainTraits<boost::mpl::vector<int, int, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, int>::total_size) & 3ul) == 0ul)' is not a valid template argument for type 'bool' because it is a non-constant expression
Environment
- Red Hat Enterprise Linux 6
- gcc-4.4
- boost
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.