$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Christoph Ludwig (cludwig_at_[hidden])
Date: 2004-06-25 04:48:37
On Thu, Jun 24, 2004 at 05:51:15PM +0200, Daniel Frey wrote:
> Robert Ramey wrote:
> >BOOST_STATIC_ASSERT(false) 
> 
> This *should* work. IMHO, if it doesn't, we should fix it, not work 
> around it like Michiel suggested.
BOOST_STATIC_ASSERT(false) expands to a typedef that does not contain
any dependent expression. I didn't check the detailed rules in my copy
of the template book by Vandevoorde and Josuttis, but I think a
compiler should check this typedef even if the function template is
not instantiated.
> >However, its doesn't work
> >with compilers that are too smart for their own good.  In order to make 
> >this
> >work I need something like:
> 
> Which compiler and which version of boost and the Compiler are you 
> using? Can you provide a minimal but complete example? Also, you might 
> want to have a look at checked_delete where we had similar problems in 
> the past IIRC.
Try the following program:
  #include <boost/static_assert.hpp>
  
  template <typename T>
  void f(T t) {
  #ifdef DEPENDENT_ASSERT_CONDITION
    BOOST_STATIC_ASSERT(sizeof(T) && false);
  #else
    BOOST_STATIC_ASSERT(false);
  #endif
  }
  
  #ifdef INSTANTIATE_F
  void g(int i) {
    f(i);
  }
  #endif
g++ 3.3.1 accepts it unless you define INSTANTIATE_F.
g++ 3.4.0 rejects it unless you define DEPENDENT_ASSERT_CONDITION (and
don't define INSTANTIATE_F, of course).
I don't know if my solution (sizeof(T) && false) has any
(dis-)advantages compared to Michiel's solution ((T*) 0).
Regards
Christoph
PS: Ramey, I patched your serialization library (based on
    serialization18.zip) such that g++ 3.4 compiles the
    examples. Besides above problem and the many errors due to the
    unqualified use of dependent names I had to work around a bug in
    libstdc++v3 (PR#16154). But I didn't have the time yet for
    extensive tests.
    If you are interested then I can send you my patches.
-- http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/cludwig.html LiDIA: http://www.informatik.tu-darmstadt.de/TI/LiDIA/Welcome.html