mapbox / mapbox/variant

Tests fail with gcc 7.0.1 due to new aliasing warnings

Open
#148 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
384
Forks
96
PR merge metrics
No merged PRs in 30d

Description

Running `make test` with gcc 7.0.1 fails due to new aliasing warnings, promoted to errors by the `-Werror` switch in the makefile:

```
g++ -c -o out/binary_visitor_1.o test/t/binary_visitor_1.cpp -Iinclude -isystem test/include -std=c++11 -Werror -Wall -Wextra -pedantic -Wformat=2 -Wsign-conversion -Wshadow -Wunused-parameter -O3 -DNDEBUG -march=native -DSINGLE_THREADED -fvisibility-inlines-hidden -fvisibility=hidden -I/usr/include/catch -pthread
In file included from test/t/binary_visitor_1.cpp:2:0:
include/mapbox/variant.hpp: In instantiation of ‘T& mapbox::util::variant::get() [with T = int; typename std::enable_if<(mapbox::util::detail::direct_type::index != mapbox::util::detail::invalid_value)>::type* = 0; Types = {int, double}]’:
test/t/binary_visitor_impl.hpp:180:9: required from here
include/mapbox/variant.hpp:724:20: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
return *reinterpret_cast(&data);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/mapbox/variant.hpp: In instantiation of ‘T& mapbox::util::variant::get() [with T = double; typename std::enable_if<(mapbox::util::detail::direct_type::index != mapbox::util::detail::invalid_value)>::type* = 0; Types = {int, double}]’:
test/t/binary_visitor_impl.hpp:187:9: required from here
include/mapbox/variant.hpp:724:20: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
include/mapbox/variant.hpp: In instantiation of ‘const T& mapbox::util::variant::get_unchecked() const [with T = int; typename std::enable_if<(mapbox::util::detail::direct_type::index != mapbox::util::detail::invalid_value)>::type* = 0; Types = {int, double}]’:
include/mapbox/variant.hpp:472:51: required from ‘static R mapbox::util::detail::binary_dispatcher::apply_const(const V&, const V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; T = int; Types = {double}]’
include/mapbox/variant.hpp:893:73: required from ‘static decltype (mapbox::util::detail::binary_dispatcher::apply_const(v0, v1, forward(f))) mapbox::util::variant::binary_visit(const V&, const V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; Types = {int, double}; decltype (mapbox::util::detail::binary_dispatcher::apply_const(v0, v1, forward(f))) = double]’
include/mapbox/variant.hpp:987:27: required from ‘decltype (V:: binary_visit(v0, v1, forward(f))) mapbox::util::apply_visitor(F&&, const V&, const V&) [with F = const add_visitor&; V = mapbox::util::variant; decltype (V:: binary_visit(v0, v1, forward(f))) = double]’
test/t/binary_visitor_impl.hpp:28:5: required from here
include/mapbox/variant.hpp:737:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
return *reinterpret_cast(&data);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/mapbox/variant.hpp: In instantiation of ‘T& mapbox::util::variant::get_unchecked() [with T = int; typename std::enable_if<(mapbox::util::detail::direct_type::index != mapbox::util::detail::invalid_value)>::type* = 0; Types = {int, double}]’:
include/mapbox/variant.hpp:493:45: required from ‘static R mapbox::util::detail::binary_dispatcher::apply(V&, V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; T = int; Types = {double}]’
include/mapbox/variant.hpp:900:67: required from ‘static decltype (mapbox::util::detail::binary_dispatcher::apply(v0, v1, forward(f))) mapbox::util::variant::binary_visit(V&, V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; Types = {int, double}; decltype (mapbox::util::detail::binary_dispatcher::apply(v0, v1, forward(f))) = double]’
include/mapbox/variant.hpp:994:27: required from ‘decltype (V:: binary_visit(v0, v1, forward(f))) mapbox::util::apply_visitor(F&&, V&, V&) [with F = const add_visitor&; V = mapbox::util::variant; decltype (V:: binary_visit(v0, v1, forward(f))) = double]’
test/t/binary_visitor_impl.hpp:68:5: required from here
include/mapbox/variant.hpp:713:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
return *reinterpret_cast(&data);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/mapbox/variant.hpp: In instantiation of ‘const T& mapbox::util::variant::get_unchecked() const [with T = double; typename std::enable_if<(mapbox::util::detail::direct_type::index != mapbox::util::detail::invalid_value)>::type* = 0; Types = {int, double}]’:
include/mapbox/variant.hpp:401:44: required from ‘static R mapbox::util::detail::binary_dispatcher_rhs::apply_const(const V&, const V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; T0 = int; T1 = double]’
include/mapbox/variant.hpp:477:80: required from ‘static R mapbox::util::detail::binary_dispatcher::apply_const(const V&, const V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; T = int; Types = {double}]’
include/mapbox/variant.hpp:893:73: required from ‘static decltype (mapbox::util::detail::binary_dispatcher::apply_const(v0, v1, forward(f))) mapbox::util::variant::binary_visit(const V&, const V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; Types = {int, double}; decltype (mapbox::util::detail::binary_dispatcher::apply_const(v0, v1, forward(f))) = double]’
include/mapbox/variant.hpp:987:27: required from ‘decltype (V:: binary_visit(v0, v1, forward(f))) mapbox::util::apply_visitor(F&&, const V&, const V&) [with F = const add_visitor&; V = mapbox::util::variant; decltype (V:: binary_visit(v0, v1, forward(f))) = double]’
test/t/binary_visitor_impl.hpp:28:5: required from here
include/mapbox/variant.hpp:737:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
return *reinterpret_cast(&data);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/mapbox/variant.hpp: In instantiation of ‘T& mapbox::util::variant::get_unchecked() [with T = double; typename std::enable_if<(mapbox::util::detail::direct_type::index != mapbox::util::detail::invalid_value)>::type* = 0; Types = {int, double}]’:
include/mapbox/variant.hpp:407:38: required from ‘static R mapbox::util::detail::binary_dispatcher_rhs::apply(V&, V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; T0 = int; T1 = double]’
include/mapbox/variant.hpp:498:74: required from ‘static R mapbox::util::detail::binary_dispatcher::apply(V&, V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; T = int; Types = {double}]’
include/mapbox/variant.hpp:900:67: required from ‘static decltype (mapbox::util::detail::binary_dispatcher::apply(v0, v1, forward(f))) mapbox::util::variant::binary_visit(V&, V&, F&&) [with F = const add_visitor&; V = mapbox::util::variant; R = double; Types = {int, double}; decltype (mapbox::util::detail::binary_dispatcher::apply(v0, v1, forward(f))) = double]’
include/mapbox/variant.hpp:994:27: required from ‘decltype (V:: binary_visit(v0, v1, forward(f))) mapbox::util::apply_visitor(F&&, V&, V&) [with F = const add_visitor&; V = mapbox::util::variant; decltype (V:: binary_visit(v0, v1, forward(f))) = double]’
test/t/binary_visitor_impl.hpp:68:5: required from here
include/mapbox/variant.hpp:713:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
return *reinterpret_cast(&data);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make: *** [Makefile:100: out/binary_visitor_1.o] Error 1
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with include/mapbox/variant.hpp, especially get() and get_unchecked(), which are reported by the failing test compilation. Run make test with gcc 7.0.1 and verify that the aliasing warnings no longer become errors and the test suite completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.