Merge pull request #2512 from kugelfuhr/kugelfuhr/fix-2134

Warn for braces around a pointer initializer
This commit is contained in:
Bob Andrews 2024-09-08 16:05:58 +02:00 committed by GitHub
commit 38038fd0d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 0 deletions

View File

@ -302,6 +302,13 @@ static unsigned ParsePointerInit (const Type* T)
/* Optional opening brace */
unsigned BraceCount = OpeningCurlyBraces (0);
/* We warn if an initializer for a scalar contains braces, because this is
** quite unusual and often a sign for some problem in the input.
*/
if (BraceCount > 0) {
Warning ("Braces around scalar initializer");
}
/* Expression */
ExprDesc ED = NoCodeConstExpr (hie1);
TypeConversion (&ED, T);

3
test/ref/bug2134.c Normal file
View File

@ -0,0 +1,3 @@
int i = { 0 };
char* p = { 0 };
int main() { return 0; }

2
test/ref/bug2134.cref Normal file
View File

@ -0,0 +1,2 @@
bug2134.c:1: Warning: Braces around scalar initializer
bug2134.c:2: Warning: Braces around scalar initializer