public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "egallager at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/110047] New: RFE: Add a warning for use of bare "unsigned" (possibly under -Wimplicit-int?)
Date: Wed, 31 May 2023 05:54:06 +0000	[thread overview]
Message-ID: <bug-110047-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110047
           Summary: RFE: Add a warning for use of bare "unsigned"
                    (possibly under -Wimplicit-int?)
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: egallager at gcc dot gnu.org
            Blocks: 87403
  Target Milestone: ---

When I was first learning C, one thing that confused me was how you can just
use plain "unsigned" as a type, without specifying the length (long, short,
int, etc.). Thus, I thought that casting to unsigned would just change the sign
like a call to abs(), without realizing that there was an implicit "int"
involved. I made a testcase:

$ cat bare_unsigned.c
#include <limits.h>

unsigned var; /* debatable */

unsigned long foo(void)
{
        long variable = LONG_MAX;
        unsigned long uvariable = (unsigned)variable; /* warn here */
        return uvariable;
}
$

The one where I added the "debatable" comment is debatable because I actually
see a lot of declarations in that form pretty often, and it's probably not very
harmful in that case, but the case with the cast, where it says "warn here", is
probably more deserving of a warning, as there's a change of size involved. It
might make sense to include this under -Wimplicit-int, or maybe create a new
warning -Wbare-unsigned for it?


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning

             reply	other threads:[~2023-05-31  5:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31  5:54 egallager at gcc dot gnu.org [this message]
2023-05-31  6:54 ` [Bug c/110047] " rguenth at gcc dot gnu.org
2023-06-01  1:11 ` egallager at gcc dot gnu.org

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-110047-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).