jnk0le / Ring-Buffer

simple C++11 ring buffer implementation, allocated and evaluated at compile time
MIT License
380 stars 64 forks source link

警告 C26495 #22

Open wfs20 opened 1 year ago

wfs20 commented 1 year ago

警告 C26495 未初始化变量 jnk0le::Ringbuffer<char const *,256,0,0,unsigned __int64>::data_buff。始终初始化成员变量(type.6)。

jnk0le commented 1 year ago

initializing this array will cause the memcpy zeroing, or calling constructors for every element

only something like this:

    //remove constructors
    alignas(cacheline_size) std::atomic<index_t> head = {}; //!< head index
    alignas(cacheline_size) std::atomic<index_t> tail = {}; //!< tail index
    alignas(cacheline_size) T data_buff[buffer_size] = {}; //!< actual buffer

doesn't emit global constructor (for POD T, on gcc)

jnk0le commented 1 year ago
    //remove constructors
    alignas(cacheline_size) std::atomic<index_t> head = {}; //!< head index
    alignas(cacheline_size) std::atomic<index_t> tail = {}; //!< tail index
    alignas(cacheline_size) T data_buff[buffer_size]; //!< actual buffer

This again emits constructors for intializing head and tail in globals/statics and warning is still there

jnk0le commented 1 year ago

[[uninitialized]] of course is not a thing.

At least for POD, llvm recognizes .bss placement and workaround constructor is not necessary.

jnk0le commented 1 year ago

non POD T constructors are always called