Drake
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
drake_assert.h File Reference

Provides Drake's assertion implementation. More...

#include <type_traits>
#include "drake/drakeCommon_export.h"
Include dependency graph for drake_assert.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DRAKE_ASSERT(condition)
 DRAKE_ASSERT(condition) is similar to the built-in assert(condition) from the C++ system header <cassert>. More...
 
#define DRAKE_ABORT_UNLESS(condition)
 Evaluates condition and iff the value is false will ::abort() the program with a message showing at least the condition text, function name, file, and line. More...
 
#define DRAKE_ABORT()
 Like DRAKE_ABORT_UNLESS(false), except that the meaningless "false" condition test is not included in the message. More...
 

Detailed Description

Provides Drake's assertion implementation.

This is intended to be used both within Drake and by other software. Drake's asserts can be armed and disarmed independently from the system-wide asserts.

Macro Definition Documentation

#define DRAKE_ABORT ( )

Like DRAKE_ABORT_UNLESS(false), except that the meaningless "false" condition test is not included in the message.

#define DRAKE_ABORT_UNLESS (   condition)

Evaluates condition and iff the value is false will ::abort() the program with a message showing at least the condition text, function name, file, and line.

#define DRAKE_ASSERT (   condition)

DRAKE_ASSERT(condition) is similar to the built-in assert(condition) from the C++ system header <cassert>.

Unless Drake's assertions are disarmed by the pre-processor definitions listed below, DRAKE_ASSERT will evaluate condition and iff the value is false will ::abort() the program with a message showing at least the condition text, function name, file, and line.

Assertions are enabled or disabled using the following pre-processor macros:

  • If DRAKE_ENABLE_ASSERTS is defined, then DRAKE_ASSERT is armed.
  • If DRAKE_DISABLE_ASSERTS is defined, then DRAKE_ASSERT is disarmed.
  • If both macros are defined, then it is a compile-time error.
  • If neither are defined, then NDEBUG governs assertions as usual.

This header will define exactly one of either DRAKE_ASSERT_IS_ARMED or DRAKE_ASSERT_IS_DISARMED to indicate whether DRAKE_ASSERT is armed.

One difference versus the standard assert(condition) is that the condition within DRAKE_ASSERT is always syntax-checked, even if Drake's assertions are disarmed.

Treat DRAKE_ASSERT like a statement – it must always be used in block scope, and must always be followed by a semicolon.