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)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 3 May 2019 22:19:40 +0000 (18:19 -0400)
commit8470daa9621083d091cb52af01eb17f35a0978b6
tree142c6f99f1ad068b1d21d58698c0b5c1d7f8582d
parent72b0443813701fc9fb23cb23684a9c8bee4667a7
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.026525 seconds and 4 git commands to generate.