include/babeltrace2: add `noexcept` specifier for C++ ≥ 11
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 25 Nov 2023 16:13:57 +0000 (11:13 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 14 Dec 2023 15:57:04 +0000 (10:57 -0500)
commit4c81a2b7cb0899f52a228249beb91f2814bbe601
treed29ddc9b8cd685ffecddb009f01a9754b517ef1e
parentf27423d42bce742b3cdc771fcbbdb2c88ee284ce
include/babeltrace2: add `noexcept` specifier for C++ ≥ 11

This patch adds the `noexcept` specifier to all the public functions
when building with C++11 and above.

This is similar to what glibc does (from `/usr/include/sys/cdefs.h`):

    #   if __cplusplus >= 201103L
    #    define __THROW noexcept (true)
    #   else
    #    define __THROW throw ()
    #   endif

and then, for example (`/usr/include/string.h`):

    /* Return the length of S.  */
    extern size_t strlen (const char *__s)
         __THROW __attribute_pure__ __nonnull ((1));

Indeed, none of our functions throw, ever, including user callbacks,
because the library always expects them to return some value (doesn't
catch, in other words).

This brings an improvement to a `noexcept` function calling a
libbabeltrace2 function. For example, consider this simple case:

    uint64_t get_cs_value(const bt_clock_snapshot * const opt_cs) noexcept
    {
        return bt_clock_snapshot_get_value(opt_cs);
    }

When bt_clock_snapshot_get_value() isn't `noexcept`, we get (`-O2`):

    get_cs_value(bt_clock_snapshot const*):
            sub     rsp, 8
            call    bt_clock_snapshot_get_value
            add     rsp, 8
            ret

With `noexcept`:

    get_cs_value(bt_clock_snapshot const*):
            jmp     bt_clock_snapshot_get_value

In other words, without this patch, there's some stack adjustment to
prepare for a possible exception when you're already in `noexcept` mode.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I0712eab48de93344159b7b7344f28b940ed81712
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11442
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
CI-Build: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
38 files changed:
include/babeltrace2/babeltrace.h
include/babeltrace2/error-reporting.h
include/babeltrace2/graph/component-class-dev.h
include/babeltrace2/graph/component-class.h
include/babeltrace2/graph/component-descriptor-set.h
include/babeltrace2/graph/component.h
include/babeltrace2/graph/connection.h
include/babeltrace2/graph/graph.h
include/babeltrace2/graph/interrupter.h
include/babeltrace2/graph/message-iterator-class.h
include/babeltrace2/graph/message-iterator.h
include/babeltrace2/graph/message.h
include/babeltrace2/graph/port.h
include/babeltrace2/graph/private-query-executor.h
include/babeltrace2/graph/query-executor.h
include/babeltrace2/graph/self-component-class.h
include/babeltrace2/graph/self-component-port.h
include/babeltrace2/graph/self-component.h
include/babeltrace2/graph/self-message-iterator.h
include/babeltrace2/integer-range-set.h
include/babeltrace2/logging.h
include/babeltrace2/plugin/plugin-loading.h
include/babeltrace2/trace-ir/clock-class.h
include/babeltrace2/trace-ir/clock-snapshot.h
include/babeltrace2/trace-ir/event-class.h
include/babeltrace2/trace-ir/event.h
include/babeltrace2/trace-ir/field-class.h
include/babeltrace2/trace-ir/field-path.h
include/babeltrace2/trace-ir/field.h
include/babeltrace2/trace-ir/packet.h
include/babeltrace2/trace-ir/stream-class.h
include/babeltrace2/trace-ir/stream.h
include/babeltrace2/trace-ir/trace-class.h
include/babeltrace2/trace-ir/trace.h
include/babeltrace2/util.h
include/babeltrace2/value.h
include/babeltrace2/version.h
src/bindings/python/bt2/bt2/native_bt.i
This page took 0.028626 seconds and 4 git commands to generate.