gul-cpp / gul14

General Utility Library for C++14
https://gul14.info/
GNU Lesser General Public License v2.1
2 stars 1 forks source link

SmallVector compiler warning #22

Closed Finii closed 1 year ago

Finii commented 1 year ago
$ c++ -Itests/libgul-test.p -Itests -I../tests -Iinclude -I../include -Isrc -I../src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++14 -O3 -pthread -MD -MQ tests/libgul-test.p/test_SmallVector.cc.o -MF tests/libgul-test.p/test_SmallVector.cc.o.d -o tests/libgul-test.p/test_SmallVector.cc.o -c ../tests/test_SmallVector.cc
In file included from /usr/include/c++/12/algorithm:60,
                 from ../tests/test_SmallVector.cc:23:
In static member function ‘static _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) [with _Tp = int; bool _IsMove = false]’,
    inlined from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = const int*; _OI = int*]’ at /usr/include/c++/12/bits/stl_algobase.h:495:30,
    inlined from ‘_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = false; _II = const int*; _OI = int*]’ at /usr/include/c++/12/bits/stl_algobase.h:522:42,
    inlined from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = const int*; _OI = int*]’ at /usr/include/c++/12/bits/stl_algobase.h:529:31,
    inlined from ‘_OI std::copy(_II, _II, _OI) [with _II = const int*; _OI = int*]’ at /usr/include/c++/12/bits/stl_algobase.h:620:7,
    inlined from ‘_OutputIterator std::__copy_n(_RandomAccessIterator, _Size, _OutputIterator, random_access_iterator_tag) [with _RandomAccessIterator = const int*; _Size = unsigned int; _OutputIterator = int*]’ at /usr/include/c++/12/bits/stl_algo.h:728:23,
    inlined from ‘_OIter std::copy_n(_IIter, _Size, _OIter) [with _IIter = const int*; _Size = unsigned int; _OIter = int*]’ at /usr/include/c++/12/bits/stl_algo.h:760:27,
    inlined from ‘gul14::SmallVector<ElementT, in_capacity>::ValueType* gul14::SmallVector<ElementT, in_capacity>::insert(ConstIterator, InputIterator, InputIterator) [with InputIterator = const int*; <template-parameter-2-2> = void; ElementT = int; long unsigned int in_capacity = 10]’ at ../include/gul14/SmallVector.h:851:20,
    inlined from ‘gul14::SmallVector<ElementT, in_capacity>::ValueType* gul14::SmallVector<ElementT, in_capacity>::insert(ConstIterator, std::initializer_list<_Tp>) [with ElementT = int; long unsigned int in_capacity = 10]’ at ../include/gul14/SmallVector.h:876:22,
    inlined from ‘void ____C_A_T_C_H____T_E_S_T____90()’ at ../tests/test_SmallVector.cc:1278:20:
/usr/include/c++/12/bits/stl_algobase.h:431:30: warning: argument 2 null where non-null expected [-Wnonnull]
  431 |             __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
      |             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12/bits/stl_algobase.h:431:30: note: in a call to built-in function ‘void* __builtin_memmove(void*, const void*, long unsigned int)’

memmove(to, from, len) is called with from == nullptr and len = 0. Anyhow, from is marked nonnull.

Reason seems to be the empty std::initializer_list that at some point, with -O3 gets optimized to nullptr. (-O2 is silent.)

Finii commented 1 year ago

Ping for @soerengrunewald

And I wanted to do Lars' taskolib PR, but that needs to compile GUL :grimacing:

Finii commented 1 year ago

Compiler that warns:

$ g++ --version
g++ (Ubuntu 12.2.0-3ubuntu1) 12.2.0

And btw

$ clang++ --version
Ubuntu clang version 15.0.2-1

is silent :grimacing: