Skip to content

clang -Warray-bounds gives a false positive when there are compilation errors #92626

Open
@fahadnayyar

Description

@fahadnayyar
#define foo(i, arr) ((i > 0) ? arr[i-1] : 0)

int main(void) {
	does_not_exist();

	int arr[] = {1, 2, 3};
	foo(0, arr);
}

clang thinks that when i is 0, we can access an out of bounds index through arr[i-1] even though we guard that access with the check (i > 0).

https://godbolt.org/z/hzfn81ds3

Metadata

Metadata

Assignees

No one assigned

    Labels

    cclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions