public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-546] [Ada] Enhance the warning on C enum with size clause for size /= 32
Date: Tue, 17 May 2022 08:29:35 +0000 (GMT)	[thread overview]
Message-ID: <20220517082935.358C53858407@sourceware.org> (raw)

https://gcc.gnu.org/g:5ab656c5e90219ce2d11a9c88d06ff927b275297

commit r13-546-g5ab656c5e90219ce2d11a9c88d06ff927b275297
Author: Etienne Servais <servais@adacore.com>
Date:   Tue Feb 15 17:59:10 2022 +0100

    [Ada] Enhance the warning on C enum with size clause for size /= 32
    
    Improve the warning message and silence warning when size > 32, this is
    likely intentional and does not warrant a warning.
    
    gcc/ada/
    
            * freeze.adb (Freeze_Enumeration_Type): Fix comment, enhance
            message and silence warning for size > 32.

Diff:
---
 gcc/ada/freeze.adb | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 381468aa687..b75f9ef07d5 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -7968,15 +7968,17 @@ package body Freeze is
 
       else
          --  If the enumeration type interfaces to C, and it has a size clause
-         --  that specifies less than int size, it warrants a warning. The
-         --  user may intend the C type to be an enum or a char, so this is
+         --  that is smaller than the size of int, it warrants a warning. The
+         --  user may intend the C type to be a boolean or a char, so this is
          --  not by itself an error that the Ada compiler can detect, but it
-         --  it is a worth a heads-up. For Boolean and Character types we
+         --  is worth a heads-up. For Boolean and Character types we
          --  assume that the programmer has the proper C type in mind.
+         --  For explicit sizes larger than int, assume the user knows what
+         --  he is doing and that the code is intentional.
 
          if Convention (Typ) = Convention_C
            and then Has_Size_Clause (Typ)
-           and then Esize (Typ) /= Esize (Standard_Integer)
+           and then Esize (Typ) < Standard_Integer_Size
            and then not Is_Boolean_Type (Typ)
            and then not Is_Character_Type (Typ)
 
@@ -7985,7 +7987,12 @@ package body Freeze is
            and then not Target_Short_Enums
          then
             Error_Msg_N
-              ("C enum types have the size of a C int??", Size_Clause (Typ));
+              ("??the size of enums in C is implementation-defined",
+               Size_Clause (Typ));
+            Error_Msg_N
+              ("\??check that the C counterpart has size of " &
+               UI_Image (Esize (Typ)),
+               Size_Clause (Typ));
          end if;
 
          Adjust_Esize_For_Alignment (Typ);


                 reply	other threads:[~2022-05-17  8:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220517082935.358C53858407@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@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).