According to https://en.cppreference.com/w/cpp/memory/unique_ptr, the pointer type of std::unique_ptr<T[]> is T* and not T[]*. However, I get the following error in cppcheck 2.14.0 (on linux):
pointer
std::unique_ptr<T[]>
T*
T[]*
portability (arithOperationsOnVoidPointer): 'buf.get()' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. Arithmetic operations on 'void *' is a GNU C extension, which defines the 'sizeof(void)' to be 1
For the following type of code:
std::unique_ptr<char[]> buf = std::make_unique<char[]>(dataSize); return buf.get() + size;
Even though that buf.get() is of type char*.
buf.get()
char*
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/12748
Thanks!
Log in to post a comment.
According to https://en.cppreference.com/w/cpp/memory/unique_ptr, the
pointer
type ofstd::unique_ptr<T[]>
isT*
and notT[]*
. However, I get the following error in cppcheck 2.14.0 (on linux):For the following type of code:
Even though that
buf.get()
is of typechar*
.Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/12748
Thanks!