Fix: headers: make static inline upcasts compatible with C++
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 27 Apr 2019 21:04:45 +0000 (17:04 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
commit005f1204d7620018bb2c1406b6194940f0ee119f
treede32d155ada220d82edd35d1058025fbdd4e8131
parent25f741168b45db9dd975136cfd3f66dbd9af39d0
Fix: headers: make static inline upcasts compatible with C++

Issue
=====
There are many static inline functions which upcast a pointer from its
original type to another one known to be a parent. The functions upcast
with `(void *)` or `(const void *)`. While this works in C, it does not
in C++, which is more strict:

    In file included from install/include/babeltrace/babeltrace.h:75,
                     from test.cpp:1:

    install/include/babeltrace/trace-ir/field-class-const.h: In function
    ‘const bt_field_class_enumeration_mapping*
    bt_field_class_unsigned_enumeration_mapping_as_mapping_const(const
    bt_field_class_unsigned_enumeration_mapping*)’:

    install/include/babeltrace/trace-ir/field-class-const.h:100:9:
    error: invalid conversion from ‘const void*’ to ‘const
    bt_field_class_enumeration_mapping*’ [-fpermissive]

      return (const void *) mapping;

Solution
========
Use the new __BT_UPCAST() and __BT_UPCAST_CONST() macros to upcast
within headers. Those macros are defined in `babeltrace/types.h`. We use
static_cast<>() in C++ with the specific destination type, going through
`void *` or `const void *` to keep the same address.

Known drawbacks
===============
None.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Iaac8e55635eb2f358a546c32bd886a484f5ebfeb
Reviewed-on: https://review.gerrithub.io/c/eepp/babeltrace/+/452302
Reviewed-by: Simon Marchi <simon.marchi@polymtl.ca>
25 files changed:
include/babeltrace/graph/component-class-filter-const.h
include/babeltrace/graph/component-class-filter.h
include/babeltrace/graph/component-class-sink-const.h
include/babeltrace/graph/component-class-sink.h
include/babeltrace/graph/component-class-source-const.h
include/babeltrace/graph/component-class-source.h
include/babeltrace/graph/component-filter-const.h
include/babeltrace/graph/component-sink-const.h
include/babeltrace/graph/component-source-const.h
include/babeltrace/graph/port-input-const.h
include/babeltrace/graph/port-output-const.h
include/babeltrace/graph/port-output-message-iterator.h
include/babeltrace/graph/self-component-class-filter.h
include/babeltrace/graph/self-component-class-sink.h
include/babeltrace/graph/self-component-class-source.h
include/babeltrace/graph/self-component-filter.h
include/babeltrace/graph/self-component-port-input-message-iterator.h
include/babeltrace/graph/self-component-port-input.h
include/babeltrace/graph/self-component-port-output.h
include/babeltrace/graph/self-component-port.h
include/babeltrace/graph/self-component-sink.h
include/babeltrace/graph/self-component-source.h
include/babeltrace/graph/self-component.h
include/babeltrace/trace-ir/field-class-const.h
include/babeltrace/types.h
This page took 0.02701 seconds and 4 git commands to generate.