Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2001-09-17 07:55:42


> > There is a historical avoidance of assert() in Boost, due to possible
ODR
> > violations. However, I believe that the new Jam build system removes
(most
> > of) this hesitance by building both debug and release versions of the
Boost
> > library. It's still possible to shoot yourself in the foot, but it's
less
> > likely.
>
> Pardon my ignorance, but what is an "ODR violation"?

ODR stands for "One Definition Rule" (see section 3.2 in the Standard).

The problem it causes for header-file libraries is if there exists in a
header some function f() that has an assert:
  template <typename T> void f(T x) { assert(x != 0); }

then if the user has a source file that calls f() and that is compiled with
NDEBUG, and another source file that calls f() and that isn't compiled with
NDEBUG, and links them together, you get: undefined behaviour (without a
diagnostic).

I've never dealt with ODR violations myself, but I've heard rumors of some
nasty debugging tales from others...

It was eventually decided (after many discussions on the list) to use
assert()'s in Boost, but to document the possibility of ODR violations.

        -Steve

For more info on ODR violations with templates:
  ISO/IEC One Definition Rule: [3.2/5]
  The C++ Programming Language (Stroustrup): [24.3.7.2]
  Boost plays with developing ODR-safe assert() replacement (never got it to
work):
    http://groups.yahoo.com/group/boost/message/637
  Boost has *long* discussion on pro's and con's of assert() and assert()
replacements:
    http://groups.yahoo.com/group/boost/message/7511


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