I am using a linked C-library to get values into a variable.
void f_wrapper(int& v){
auto s = f_legacy(&v);
if(s != success) throw std::runtime_error{};
}
...
int value; // clang-tidy complains here: using "variable 'value' is not initialized"
f_wrapper(value);
However, clang-tidy complains here: using "variable 'value' is not initialized".
As far as understand, this is simply because the compiler cannot see through the linked function.
I don't want to do int value = 0
(because I trust that the library will initialize value
and I believe in "partially formed" values.)
Also, I am looking not to add // NOLINT(warning)
just to suppress the warning.
(The pattern repeats often.)
Is there something I could do mark value
as initialized in the language?
I am looking for something like:
void f_wrapper(int& v) {
auto s = f_legacy(&v);
if(s != success) throw std::runtime_error{};
[[mark initialized(v)]];
}
Worst case I can do this inside the wrapper, because at least I don't see the unnecessary initialization the main code, but it is very cumbersome in cases where arrays are initialized. Also I don't want to pay the prize of this initialization or choose a default value.
void f_wrapper(int& v) {
v = int{}; // initialize to suppress warning at high level code
auto s = f_legacy(&v);
if(s != success) throw std::runtime_error{};
}