clang ++ libc ++ инициализация векторасо значением - PullRequest
0 голосов
/ 19 мая 2018

Я обновляю старый проект до новейшей системы сборки Android.Android Studio 3.1.2 и clang / libc ++.Проект использует https://github.com/MJPA/SimpleJSON и не может скомпилировать, как это было с gcc.
Я не знаю, как vector реализован в libc ++, но кажется, что конструктор по умолчанию пытается создать JSONValue * сNULL или что-то, и это не удается?Возможно ли, что я не включил правильное определение в компиляции?Специализация шаблона в include / memory находится внутри блока, который определяется только тогда, когда _LIBCPP_CXX03_LANG - нет.Я проверил, и это единственное место в источнике, где это определение проверяется.Я компилирую с -std = c ++ 11, будет ли это включать функциональность CXX03?:

class JSONValue;
typedef std::vector<JSONValue *> JSONArray;
class JSONValue
{
    friend class JSON;

    public:
        JSONValue(/*NULL*/);
        JSONValue(const TCHAR *m_char_value);
        JSONValue(const tstring &m_string_value);
        JSONValue(bool m_bool_value);
        JSONValue(double m_number_value);
        JSONValue(const JSONArray &m_array_value);
        JSONValue(const JSONObject &m_object_value);
        ~JSONValue();

        JSONValue *Clone() const;

        bool IsNull() const;
        bool IsString() const;
        bool IsBool() const;
        bool IsNumber() const;
        bool IsArray() const;
        bool IsObject() const;

        // change the internal type of the JSONValue so that we can keep the contained objects around for
        // another instance to clean up. be VERY careful about using this unless you know how to clean up
        // memory in a map of pointers on your own. This is major hack territory but it was the fastest
        // way to fix a double free without completely changing the printer discovery call chain.
        void Detach(void) { type = JSONType_Null; };

        const tstring &AsString() const;
        bool AsBool() const;
        double AsNumber() const;
        const JSONArray &AsArray() const;
        const JSONObject &AsObject() const;

        tstring Stringify() const;

        JSONValue* CopyObjectField(const TCHAR *fieldname);

    protected:
        static JSONValue *Parse(const TCHAR **data);

    private:
        static tstring StringifyString(const tstring &str);
        JSONValue *CloneSimpleValue(const JSONValue *);
        JSONValue *RecursiveCloneObject(const JSONObject &inobj) const;
        JSONValue *RecursiveCloneArray(const JSONArray &inarray) const;
        JSONType type;
        tstring string_value;
        bool bool_value;
        double number_value;
        JSONArray array_value;
        JSONObject object_value;
};

JSONValue array;

Создание экземпляра объекта JSONValue вызывает следующую ошибку во время компиляции:

 FAILED: C:\Users\kmurphy\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=x86_64-none-linux-android --gcc-toolchain=C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sysroot   -ID:/SPTX/Include -isystem C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include -isystem C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/android/support/include -isystem C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include -isystem C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++11 -frtti -fexceptions -x c++ -O0 -fno-limit-debug-info  -fPIC -MD -MT D:/SPTX/Builds/Android/tlibJSON/x86_64/CMakeFiles/tlibJSON.dir/JSONValue.cpp.o -MF D:\SPTX\Builds\Android\tlibJSON\x86_64\CMakeFiles\tlibJSON.dir\JSONValue.cpp.o.d -o D:/SPTX/Builds/Android/tlibJSON/x86_64/CMakeFiles/tlibJSON.dir/JSONValue.cpp.o -c D:\SPTX\Projects\Parsers\tlibJSON\JSONValue.cpp
  In file included from D:\SPTX\Projects\Parsers\tlibJSON\JSONValue.cpp:25:
  In file included from D:\SPTX\Projects\Parsers\tlibJSON/stdafx.h:6:
  In file included from D:/SPTX/Include/tlibTYPES_android.h:16:
  In file included from C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\string:470:
  In file included from C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\string_view:169:
  In file included from C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\__string:56:
  In file included from C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\algorithm:643:
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\memory:2050:9: error: cannot initialize a member subobject of type 'JSONValue **' with an rvalue of type 'long'
        : __value_(_VSTD::forward<_Up>(__u)){};
          ^        ~~~~~~~~~~~~~~~~~~~~~~~~
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\memory:2135:9: note: in instantiation of function template specialization 'std::__ndk1::__compressed_pair_elem<JSONValue **, 0, false>::__compressed_pair_elem<long, void>' requested here
        : _Base1(std::forward<_Tp>(__t)), _Base2() {}
          ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\vector:423:7: note: in instantiation of function template specialization 'std::__ndk1::__compressed_pair<JSONValue **, std::__ndk1::allocator<JSONValue *> >::__compressed_pair<long, true>' requested here
        __end_cap_(nullptr)
        ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\vector:473:5: note: in instantiation of member function 'std::__ndk1::__vector_base<JSONValue *, std::__ndk1::allocator<JSONValue *> >::__vector_base' requested here
      vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
      ^
  D:\SPTX\Projects\Parsers\tlibJSON\JSONValue.cpp:228:13: note: in instantiation of member function 'std::__ndk1::vector<JSONValue *, std::__ndk1::allocator<JSONValue *> >::vector' requested here
                  JSONArray array;
                            ^
  In file included from D:\SPTX\Projects\Parsers\tlibJSON\JSONValue.cpp:25:
  In file included from D:\SPTX\Projects\Parsers\tlibJSON/stdafx.h:6:
  In file included from D:/SPTX/Include/tlibTYPES_android.h:16:
  In file included from C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\string:470:
  In file included from C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\string_view:169:
  In file included from C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\__string:56:
  In file included from C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\algorithm:643:
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\memory:2145:9: error: no matching constructor for initialization of '__compressed_pair_elem<JSONValue **, 0>'
        : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
          ^      ~~~~~~~~~~~~~~~~~~~~~~~
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\__split_buffer:309:7: note: in instantiation of function template specialization 'std::__ndk1::__compressed_pair<JSONValue **, std::__ndk1::allocator<JSONValue *> &>::__compressed_pair<long, std::__ndk1::allocator<JSONValue *> &>' requested here
      : __end_cap_(nullptr, __a)
        ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\vector:1567:49: note: in instantiation of member function 'std::__ndk1::__split_buffer<JSONValue *, std::__ndk1::allocator<JSONValue *> &>::__split_buffer' requested here
      __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
                                                  ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\vector:1588:9: note: in instantiation of function template specialization 'std::__ndk1::vector<JSONValue *, std::__ndk1::allocator<JSONValue *> >::__push_back_slow_path<JSONValue *const &>' requested here
          __push_back_slow_path(__x);
          ^
  D:\SPTX\Projects\Parsers\tlibJSON\JSONValue.cpp:256:10: note: in instantiation of member function 'std::__ndk1::vector<JSONValue *, std::__ndk1::allocator<JSONValue *> >::push_back' requested here
                          array.push_back(value);
                                ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\memory:2037:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'long' to 'const std::__ndk1::__compressed_pair_elem<JSONValue **, 0, false>' for 1st argument
  struct __compressed_pair_elem {
         ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\memory:2037:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'long' to 'std::__ndk1::__compressed_pair_elem<JSONValue **, 0, false>' for 1st argument
  struct __compressed_pair_elem {
         ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\memory:2049:3: note: candidate template ignored: substitution failure [with _Up = long, $1 = void]
    __compressed_pair_elem(_Up&& __u)
    ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\memory:2054:3: note: candidate constructor template not viable: requires 3 arguments, but 1 was provided
    __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
    ^
  C:/Users/kmurphy/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include\memory:2043:13: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
    constexpr __compressed_pair_elem() : __value_() {}
              ^
  2 errors generated.
  ninja: build stopped: subcommand failed.

1 Ответ

0 голосов
/ 19 мая 2018

Кто-то #define nullptr 0, и это то, что ломает это.Это не вина STL.Вы должны найти того, кто владеет #define nullptr, и попросить его остановиться.

...