There is a part of code:
void func0(xxx* obj)
{
void* ptr;
size_t size;
obj->getBuffer(ptr, size); // Init ptr & size
while(size) // ERROR: may be used uninitialized
{
// processing buffer
}
}
'xxx.h'
#include <cstddef>
class xxx
{
public:
xxx();
xxx(void* p, size_t s);
void getBuf(void*& p, size_t& s);
private:
void* pp;
size_t ss;
};
'xxx.cpp'
#include "xxx.h"
xxx::xxx()
{
pp = (void*)0xFFFF;
ss = 0x100;
}
xxx::xxx(void* p, size_t s)
{
pp = p;
ss = s;
}
void xxx::getBuf(void*& p, size_t& s)
{
p = pp;
s = ss;
}
GCC generates 'may be used uninitialized in this function' error.
GCC version: 'aarch64-elf-g++ (GNU Toolchain for the A-profile Architecture 8.2-2018-08 (arm-rel-8.23)) 8.2.1 20180802'
Is there a way to hint compiler that variables are actually inited without explicitly assign them with some default values in declaration?
PS: Error comes with a new version of toolchain.
please no 'rewrite everything' / 'bad design' advices.
getBuffer
attributes. For example, for nowgetBuffer
assigns variables always. Lets say it's modified and skips initialization of a parameter. "-Wuninitialized" would suppress a warning, while variable is indeed uninited. Additional inconvenience of this way thatgetBuffer
is used in different files, all these files should be modified. Changing multiple files, rather than only one, is exactly what I want to avoid.