https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113769
Bug ID: 113769 Summary: GCC fails to warn of integer being used uninitialized Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: symbioticfemale at cumallover dot me Target Milestone: --- // The "used uninitialized" warning is not produced on both GCC and Tiny Compiler. Clang recognizes the error. (-Wall on all compilers). See line comments for further explanation. The latest version of GCC I've tested with is 13.2.1. // Version 1: With printf #include <stdio.h> #include <stdint.h> #include <pthread.h> pthread_rwlock_t necessary_lock = PTHREAD_RWLOCK_INITIALIZER; void do_nothing(const void *value); void do_nothing(const void *value) { printf("%p\n",value); // do anything on value other than (void) value } int main(void) { pthread_rwlock_rdlock(&necessary_lock); pthread_rwlock_unlock(&necessary_lock); // Fun fact: remove either the pthread_rwlock_rdlock + pthread_rwlock_unlock, or the printf in do_nothing, and GCC catches the lack of initialization uint32_t pos; pos += 1; do_nothing(&pos); printf("%u\n",pos); } // Version 2: Without printf #include <stdio.h> #include <stdint.h> #include <pthread.h> pthread_rwlock_t necessary_lock = PTHREAD_RWLOCK_INITIALIZER; void do_nothing(const void *value); void do_nothing(const void *value) { (void) value; } int main(void) { pthread_rwlock_rdlock(&necessary_lock); pthread_rwlock_unlock(&necessary_lock); // Fun fact: remove either the pthread_rwlock_rdlock + pthread_rwlock_unlock, or the do_nothing function call, and GCC catches the lack of initialization. Add a printf after do_nothing and GCC will also catch it. uint32_t pos; pos += 1; do_nothing(&pos); }