Skip to content

assert in headers

Even if the installed library has been compiled with -DNDEBUG, some of the installed header have inline functions with assert() that are injected into any code using Spot, but compiled with -DNDEBUG.

Is this desirable?

One example is in graph.hh, where most very low-level functions like edge_storage() and state_storage() first do something like assert(s < edges_.size()); return edges_[s];. This is checked every time we access a transition, and unfortunately computation of edges_.size() involves a division by 20 (the size of an edge) on my system.

A loop like

    for (auto& e: aut->out(s))
         f(e.dst);

would have to recompute edges_.size() at each iteration (in case f() changed it).

I would suggest to drop those very frequent asserts, and just rely -D_GLIBCXX_DEBUG when we need to troubleshoot STL containers.

For other assert() that appear in public header, we should probably wrap them in a SPOT_ASSERT() macro that is disabled in releases. Plus relevant sanity checks to forbid assert() in headers.

  • add an --enable-glibcxx-debug configure option, and document it
  • configure one of the builds on teamcity to use that option
  • get rid of assert() that can be done by -D_GLIBCXX_DEBUG such as those in edge_storage() and state_storage()
  • introduce a SPOT_ASSERT() macro, use it, and add a sanity check to prevent the introduction of assert in headers
Edited by Alexandre Duret-Lutz