-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Open
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Description
Since the commit b247698 and associated pull request #157364 the following code:
#include <stdio.h>
int afunc(unsigned long * v)
{
return v != NULL;
}
unsigned long mdarr[5][6];
unsigned long sdarr[30];
int main()
{
afunc(sdarr);
afunc(mdarr);
printf("mdarr = %zu \n", sizeof(mdarr));
printf("sdarr = %zu \n", sizeof(sdarr));
return 0;
}
generate an error:
error: incompatible pointer types passing 'unsigned long[5][6]' to parameter of type 'unsigned long *' [-Wincompatible-pointer-types]
.
Please see godbolt example.
However the ISO/IEC 9899:1999 standard in 6.5.2.1 Array subscripting says:
If E is an n-dimensional array (n ≥ 2) with dimensions i × j × . . . × k, then E (used as other than an lvalue) is converted to a pointer to an (n − 1)-dimensional array with dimensions j × . . . × k. If the unary * operator is applied to this pointer explicitly, or implicitly as a result of subscripting, the result is the pointed-to (n − 1)-dimensional array, which itself is converted into a pointer if used as other than an lvalue.
effectively requiring compatibility between multidimensional array and pointer. Thus it looks like a diagnostics should not be generated in such case as standard compliant compiler should guarantee compatibility between all 3 types unsigned long *
, unsigned long [5][6]
, unsigned long [30]
.
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer