Plugin adding a new warning for C: detection of suspicious variable assignment in struct initialization

GRASSET Judicaël judicael.grasset@meteo.fr
Sun Dec 21 13:14:00 GMT 2025


Hello, 

Find attached a plugin for GCC 14. It detects when the user forgets a dot and initialize by mistake a local variable instead of a struct member. 
I am not aware of any warning of gcc that can detect this mistake, but it would be nice to not have to use a plugin for that, so if you know any flag to check that please share it. 
It is helpful for me, so I am posting it thinking it might help someone else. 

I am not at all familiar with the gcc internals, so I did not write this plugin myself: *it has been vibe-coded with claude.ai* 
I have been able to compile and run it correctly on Debian 13, using GCC 14.2. 

Usage example: 

typedef struct { 
int a, b, c; 
} t; 

int c = 0; 

t f1() { 
return (t){.a=1, .c=c}; // OK 
} 

t f3() { 
return (t){.a=1, c=1}; // Should generate a warning 
} 

test.c: In function ‘f3’: 
test.c:16:23: warning: assignment 'c=...' in initializer context - did you mean '.c=...'? 
16 | return (t){.a=1, c=1}; // Should generate a warning 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: designated_init_checker.cpp
Type: text/x-csrc
Size: 5355 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20251221/736ff90a/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: text/x-makefile
Size: 475 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20251221/736ff90a/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-c++src
Size: 550 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20251221/736ff90a/attachment-0002.bin>


More information about the Gcc mailing list