https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106797

            Bug ID: 106797
           Summary: Improvement: diagnose undefined behavior: not all
                    declarations that refer to the same object or function
                    have compatible type
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pavel.morozkin at gmail dot com
  Target Milestone: ---

This code:
static int (*x)[];

void f1(void)
{
    extern int (*x)[3];
}

void f2(void)
{
    extern int (*x)[5];
}

compiled with -std=c11 -pedantic -Wall -Wextra -Wno-unused-variable triggers UB
(see below) and leads to no diagnostics. It is proposed to produce this (or
similar) diagnostics: "not all declarations that refer to the same object x
have compatible type" OR "declarations that refer to the same object x have
types 'int (*)[5]' and 'int (*)[3]' which are not compatible".

Relevant quote from C11, 6.2.7 Compatible type and composite type, 2:
> All declarations that refer to the same object or function shall have 
> compatible type; otherwise, the behavior is undefined.

In the program above types 'int (*)[5]' and 'int (*)[3]' are not compatible. It
is useful to diagnose that.

Reply via email to