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)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:12:56 +0000 (00:12 -0400)
commit9f7a7546c45e7501e749d19ebad3a31b7d715ef6
treede32d155ada220d82edd35d1058025fbdd4e8131
parent06f6b99e7d38280531eb21f976c180c1b8e8534c
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.025836 seconds and 5 git commands to generate.