public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pavel.morozkin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/106797] New: Improvement: diagnose undefined behavior: not all declarations that refer to the same object or function have compatible type
Date: Wed, 31 Aug 2022 19:20:15 +0000	[thread overview]
Message-ID: <bug-106797-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2022-08-31 19:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 19:20 pavel.morozkin at gmail dot com [this message]
2022-08-31 19:24 ` [Bug c/106797] " jsm28 at gcc dot gnu.org
2022-08-31 19:28 ` pavel.morozkin at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-106797-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).