Boost logo

Boost :

From: Craig Henderson (cdm.henderson_at_[hidden])
Date: 2003-03-09 08:09:01


Hi all,

I have stumbled across a problem using the BCC5.5.1 compiler that may
highlight an incompatibility with the BOOST_NO_INCLASS_MEMBER_INITIALIZATION
macro. The problem is best described by way of an example, so I have pasted
a complete repro case below.

The problem comes about using the BOOST_STATIC_CONSTANT macro that is
defined in config/suffix.hpp dependent on the definition of
BOOST_NO_INCLASS_MEMBER_INITIALIZATION. For BCC5.5.1 (a compiler with which
I am not yet familiar), this macro is not defined. As a result, the
BOOST_STATIC_CONSTANT macro expands to define a constant in the normal way
rather than using the enum workaround.

This is all very good, and works a dream in most situations. However, I have
a situation where BCC refuses to use the static constant as a template
parameter. It gives error E2231: Member myval2<T>::value cannot be used
without an object

I think this is probably a compiler bug. GCC3.2 compiles the code cleanly.
If I replace the offending line with
    enum { value=T::value };
then BCC also builds cleanly.

So my questions are these:
1) If this is a known issue with the compiler?
2) Can/should the boost configuration be altered to work around the problem?

Note that for VC7.0, the BOOST_NO_INCLASS_MEMBER_INITIALIZATION macros is
defined, when the compiler does support inline member initialization, but
also has problems in using such constants in template parameters.

Regards
-- Craig

#include <boost/config.hpp>

#ifdef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
#pragma message ("BOOST_NO_INCLASS_MEMBER_INITIALIZATION defined")
#endif

template<int Value>
struct myval
{
    BOOST_STATIC_CONSTANT(int, value=Value);
};

template<typename T>
struct myval2
{
    BOOST_STATIC_CONSTANT(int, value=T::value);

    myval<value> myval_obj; // <-- BCC error E2231
};

int main(int, char **)
{
    typedef
    myval<7>
    myseven;

    myval2<myseven> val;

    return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk