Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Support for compiling with clang++ >= 3.9.1 #7702

Closed

Description

@springmeyer

We currently hit errors due to warnings with clang++ 3.9.1. This is because the enum.hpp header emits a warning with -Wundefined-var-template which is newly added to clang++ and enabled by default: http://llvm.org/viewvc/llvm-project?view=revision&revision=266719.

@kkaefer @jfirebaugh - any ideas to work around? Or should we suppress?

../../../include/mbgl/util/enum.hpp:17:32: error: instantiation of variable 'mbgl::Enum<mbgl::style::SymbolPlacementType>::begin' required here, but no definition is available [-Werror,-Wundefined-var-template]
        auto it = std::find_if(begin, end, [&] (const auto& v) { return t == v.first; });
                               ^
../../../src/mbgl/style/conversion/stringify.hpp:52:28: note: in instantiation of member function 'mbgl::Enum<mbgl::style::SymbolPlacementType>::toString' requested here
    writer.String(Enum<T>::toString(v));
                           ^
../../../src/mbgl/style/conversion/stringify.hpp:236:39: note: in instantiation of function template specialization 'mbgl::style::conversion::stringify<rapidjson::Writer<rapidjson::GenericStringBuffer<rapidjson::UTF8<char>, rapidjson::CrtAllocator>, rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator, 0>, mbgl::style::SymbolPlacementType, void>' requested here
    v.evaluate([&] (const auto& v_) { stringify(writer, v_); });
                                      ^
../../../mason_packages/headers/variant/1.1.4/include/mapbox/variant.hpp:304:51: note: in instantiation of member function 'mapbox::util::detail::dispatcher<const (lambda at ../../../src/mbgl/style/conversion/stringify.hpp:236:16) &, mapbox::util::variant<mbgl::style::Undefined, mbgl::style::SymbolPlacementType, mbgl::style::Function<mbgl::style::SymbolPlacementType> >, void, mbgl::style::SymbolPlacementType, mbgl::style::Function<mbgl::style::SymbolPlacementType> >::apply_const' requested here
            return dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f));
                                                  ^
../../../mason_packages/headers/variant/1.1.4/include/mapbox/variant.hpp:850:55: note: in instantiation of member function 'mapbox::util::detail::dispatcher<const (lambda at ../../../src/mbgl/style/conversion/stringify.hpp:236:16) &, mapbox::util::variant<mbgl::style::Undefined, mbgl::style::SymbolPlacementType, mbgl::style::Function<mbgl::style::SymbolPlacementType> >, void, mbgl::style::Undefined, mbgl::style::SymbolPlacementType, mbgl::style::Function<mbgl::style::SymbolPlacementType> >::apply_const' requested here
        return detail::dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f));
                                                      ^
../../../include/mbgl/style/property_value.hpp:44:23: note: in instantiation of function template specialization 'mapbox::util::variant<mbgl::style::Undefined, mbgl::style::SymbolPlacementType, mbgl::style::Function<mbgl::style::SymbolPlacementType> >::visit<const (lambda at ../../../src/mbgl/style/conversion/stringify.hpp:236:16) &, mapbox::util::variant<mbgl::style::Undefined, mbgl::style::SymbolPlacementType, mbgl::style::Function<mbgl::style::SymbolPlacementType> >, void>' requested here
        return Value::visit(value, evaluator);
                      ^
../../../src/mbgl/style/conversion/stringify.hpp:243:9: note: in instantiation of function template specialization 'mbgl::style::conversion::stringify<rapidjson::Writer<rapidjson::GenericStringBuffer<rapidjson::UTF8<char>, rapidjson::CrtAllocator>, rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator, 0>, mbgl::style::SymbolPlacementType>' requested here
        stringify(writer, value);
        ^
../../../src/mbgl/style/conversion/stringify.hpp:250:21: note: in instantiation of function template specialization 'mbgl::style::conversion::stringify<mbgl::style::SymbolPlacement, rapidjson::Writer<rapidjson::GenericStringBuffer<rapidjson::UTF8<char>, rapidjson::CrtAllocator>, rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator, 0>, mbgl::style::SymbolPlacementType>' requested here
    util::ignore({ (stringify<Ps>(writer, ps.unevaluated.template get<Ps>()), 0)... });
                    ^

Activity

  1. springmeyer commented on Jan 12, 2017

    @springmeyer
    ContributorAuthor

    A second issue needing addressed to support clang >= 3.9.1 is this failure in the tests:

    /home/travis/build/mapbox/mapbox-gl-native/test/api/annotations.test.cpp:76:32: error: no matching constructor for initialization of 'const mapbox::geometry::linear_ring<double, std::vector>'
        Polygon<double> polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }};
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:264:7: note: candidate inherited constructor not viable: cannot convert initializer list argument to 'const allocator_type' (aka 'const std::allocator<mapbox::geometry::point<double> >')
          vector(const allocator_type& __a) noexcept
          ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:277:7: note: candidate inherited constructor not viable: cannot convert initializer list argument to 'size_type' (aka 'unsigned long')
          vector(size_type __n, const allocator_type& __a = allocator_type())
          ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:318:7: note: candidate inherited constructor not viable: cannot convert initializer list argument to 'const std::vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >'
          vector(const vector& __x)
          ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:335:7: note: candidate inherited constructor not viable: cannot convert initializer list argument to 'std::vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >'
          vector(vector&& __x) noexcept
          ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:373:7: note: candidate inherited constructor not viable: cannot convert initializer list argument to 'mapbox::geometry::point<double>'
          vector(initializer_list<value_type> __l,
          ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:13:8: note: candidate constructor (the implicit copy constructor) not viable: cannot convert initializer list argument to 'const mapbox::geometry::linear_ring<double, std::vector>'
    struct linear_ring : Cont<point<T>>
           ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:13:8: note: candidate constructor (the implicit move constructor) not viable: cannot convert initializer list argument to 'mapbox::geometry::linear_ring<double, std::vector>'
    struct linear_ring : Cont<point<T>>
           ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:401:9: note: candidate inherited constructor template not viable: requires at least 2 arguments, but 1 was provided
            vector(_InputIterator __first, _InputIterator __last,
            ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:13:8: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided
    struct linear_ring : Cont<point<T>>
           ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:339:7: note: candidate inherited constructor not viable: requires 2 arguments, but 1 was provided
          vector(const vector& __x, const allocator_type& __a)
          ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:348:7: note: candidate inherited constructor not viable: requires 2 arguments, but 1 was provided
          vector(vector&& __rv, const allocator_type& __m)
          ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:289:7: note: candidate inherited constructor not viable: requires at least 2 arguments, but 1 was provided
          vector(size_type __n, const value_type& __value,
          ^
    ../../../mason_packages/headers/geometry/0.9.0/include/mapbox/geometry/polygon.hpp:18:27: note: constructor from base class 'vector<mapbox::geometry::point<double>, std::allocator<mapbox::geometry::point<double> > >' inherited here
        using container_type::container_type;
                              ^
    /usr/lib/gcc/x86_64-linux-gnu/5.4.1/../../../../include/c++/5.4.1/bits/stl_vector.h:373:43: note: passing argument to parameter '__l' here
          vector(initializer_list<value_type> __l,
                                              ^
    
  2. springmeyer commented on Jan 12, 2017

    @springmeyer
    ContributorAuthor

    The no matching constructor for initialization is replicable on OS X and may be a clang 3.9.x bug. I can replicate with 3.9.0 and 3.9.1 and not 3.8.1 or 4.0.0 (head) with:

    #include <mapbox/geometry/polygon.hpp>
    
    int main() {
        mapbox::geometry::polygon<double> polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }};
    }
  3. springmeyer commented on Jan 12, 2017

    @springmeyer
    ContributorAuthor

    I found that:

    mapbox::geometry::polygon<double> polygon = { {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} };
    

    Works around the compile error (and produces the right polygon still). Perhaps this is our bug and clang++ 3.9 is being more strict? Or could this be compiler bug...

  4. springmeyer commented on Jan 12, 2017

    @springmeyer
    ContributorAuthor

    429016b works around the polygon ctor issue.

  5. added
    Core
    on Jan 13, 2017
  6. jfirebaugh commented on Jan 17, 2017

    @jfirebaugh
    Contributor

    I can't find any documentation of -Wundefined-var-template, only discussion in the code review implementing it and in a prior attempt at implementing it. This seems to be the issue that led to someone adding it.

    As far as I can tell from the discussion, our code is valid, falling under the "uncommon, but an idiom used by some" category discussed in the second link, which suggests a workaround:

    For valid code, this means we'd warn on templates/temploids which have their definition and all relevant explicit instantiations tucked away in some source file (but for which no explicit instantiation declarations are provided in the relevant header file) -- uncommon, but an idiom used by some. There is at least a syntactic solution we can suggest for people who see the warning: add the missing explicit instantiation declarations to the header file.

    This would mean (re-)introducing a MBGL_DECLARE_ENUM macro and using it in the appropriate header file corresponding to each use of MBGL_DEFINE_ENUM. The definition would be something like:

    #define MBGL_DECLARE_ENUM(type) \
    extern template const Enum<type>::Value* Enum<type>::begin; \
    extern template const Enum<type>::Value* Enum<type>::end;
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Corebuild

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions