[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c/106797] New: Improvement: diagnose undefined behavior: not all declarations that refer to the
From:       "pavel.morozkin at gmail dot com via Gcc-bugs" <gcc-bugs () gcc ! gnu ! org>
Date:       2022-08-31 19:20:15
Message-ID: bug-106797-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

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.=


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic