Calling a function with uninitalized struct variable as a parameter doesn't produce a warning

Viewed 279

I have the following code in c++:

#include <iostream>

typedef struct Pair{
  int x;
  int y;
}Pair;

void dumFun(Pair p){}

int main() {
    Pair p;
    
    if (0){
      p = {1,2};
    }
    
    dumFun(p);
    return 0;
}          
             

When I compiled the code, I expected to get a warning for the line with dumFun(p) since I'm calling a function with an uninitialized variable.
What I actually want is that my Makefile will give me warning for uninitialized scalar variable issues that I see with the tool Coverity.

Tried to use flag -Wall and I thought it shows warnings for unused variables usage as this - but it doesn't.

Is there any flag to use on a Makefile that will show me warning for the line I wrote above?

1 Answers

You did not tell the compiler, but at least in Clang there is no warning that would catch this. -Weverything shows all possible warnings, and you can use it to find the specific parameter needed to trigger each warning. Demonstration with -Weverything shows no warnings.

I did not find a suitable parameter in GCC either.

Related