Skip to content
Snippets Groups Projects

Add macro DUNE_ASSERT_AND_RETURN

Merged Carsten Gräser requested to merge feature/assert-and-return into master
  1. Oct 17, 2016
    • Carsten Gräser's avatar
      [test] Add test for DUNE_ASSERT_AND_RETURN · 63c0a712
      Carsten Gräser authored
      Since dune_add_test(... EXPECT_FAIL) does not work with
      failing assertions, we cannot check if an actual runtime
      assertion was triggered, but only the compile-time case.
      63c0a712
    • Carsten Gräser's avatar
      Use DUNE_ASSERT_AND_RETURN · 0ed3254b
      Carsten Gräser authored
      0ed3254b
    • Carsten Gräser's avatar
      Add macro DUNE_ASSERT_AND_RETURN · 3103ae8b
      Carsten Gräser authored
      In C++11 and with not fully C++14 compliant compilers `constexpr` functions
      can only have a return statement. This prevents the use of `assert()` inside
      of `constexpr` functions. This macro can be used as a workaround like this:
      
        constexpr auto foo(int a, int b, int x)
        {
          return DUNE_AND_RETURN(a<b, x);
        }
      
      For `NDEBUG` there is no penalty. Otherwise there are two options:
      * In a non-`constexpr` context an `assert()` will fail if the condition
        is not matched. The error message will be slightly different from a
        classic assertion.
      * In a `constexpr` context the `assert()` branch will be ignored if the
        is condition is matched. Otherwise this will lead to a compile error
        (like `static_assert`) because the branch using `assert()` is not `constexpr`.
      3103ae8b
Loading