Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-09-05 12:13:35


----- Original Message -----
From: John Maddock <John_Maddock_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, September 05, 2001 8:29 AM
Subject: [boost] aligned_storage<> and optional<>

>
> >Initially, I couldn't compile Douglas code because Borland C++ 5.5 kept
> >crashing with an internal compiler error.
>
> Have you tried 5.51 - it's much more stable than 5.50 if that's what you
> are using...
>
Do you mean update patch #1? That's what I have installed.

> >First, although the borland compiler does recognize:
> > static const int v = 1 ;
> >it seems to treat it differently than:
> > enum { v = 1 } ;
> >since the former can't be used as a non-type template parameter while the
> >later can.
> >
> >This forced me to wrap constants defined with BOOST_STATIC_CONSTANT in
> >an enum.
>
> That's not my experience - provided you are careful you can use
> BOOST_STATIC_CONSTANT (see more/int_const_guidelines.htm for all the
> workarounds you may need) - I've also found that while you can nearly
> always use enum's in constant expressions, they sometimes have a garbage
> value (usually zero) when used in that way. Since this is a silent
> failure, it's generally best to use static const int's, that way you know
> when there is a problem.
>

I boiled down the problem to the following:

template<int N> struct A {} ;

struct B
{
  static const int v = 1 ;
  char b[v] ;
  A<v> n ;
} ;

template<class T>
struct C0
{
  static const int v = 1 ;
  char b[v] ;
  A<v> n ; // <=== ERROR HERE
} ;

template<class T>
struct C1
{
  enum { v = 1 } ;
  char b[v] ;
  A<v> n ;
} ;

In the error line it shows:

  Member C0<T>::v cannot be used without an object.
  Cannot generate template specialization from 'A<N>'
  Declaration terminated incorrectly

Notice that class B is equivalent to C0<T>, except that it is not a
template; an compiles just fine.

C0<T>::char b[v] shows that v is properly declared as a constant integer
expression, so the problem doesn't appear to be in 'v' itslef but in its
usage as the non-type template argument in A<>.

C1 shows that if I change the declaration of v to an 'enum' the problem
disappears.

Could you verify that this happens to you too?

Thanks,

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


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