Skip to content

Potentially misleading diagnistics in -Wconditional-uninitialized #125292

@earnol

Description

@earnol

The conditional-uninitialized diagnostics checker issue warnings even in cases when the initialization is clearly performed.
Here is the example:

int a(int p1) 
{    
  int cv = 1;
  int ibn;
  if ((cv < 5) && (p1 == 1))
  {
    ibn = 2;
    p1 += 1;
    cv++;
  }
  if(cv == 2)
  {
    return ibn; 
  } 
  return 8;
}

The warning generated is: "warning: variable 'ibn' may be uninitialized when used here [-Wconditional-uninitialized]".
In this case depending on the passed value p1 the variable ibn might be not initialized when used in the return statement.
However the code is written in such way that variable return ibn; line is executed only when ibn = 2; is also executed. Thus the warning is technically superfluous.
The godbolt example to play with: https://godbolt.org/z/qnhq9YE61.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions