public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ppluzhnikov at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/58709] [c++11] Bogus? int vs. scoped enum printf warning when -fabi-version >= 6
Date: Sun, 13 Oct 2013 14:30:00 -0000	[thread overview]
Message-ID: <bug-58709-4-ti5jOkR8Nd@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-58709-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58709

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jdennett at google dot com
         Resolution|---                         |INVALID

--- Comment #4 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
James Dennett says:

I believe that the code is incorrect, and the warning is valid.

For calls via varargs:

       .       If the argument has integral or enumeration type that is subject
to the integral promotions (4.5), or a floating point type that is subject to
the floating point promotion (4.6), the value of the argument is converted to
the promoted type before the call. These promotions are referred to as the
default argument promotions.

And scoped enumerations are not "subject to the integral promotions"; only
unscoped enums are:

       .       The value of an enumerator or an object of an unscoped
enumeration type is converted to an integer by integral promotion (4.5).

So it (the scoped enumeration value) is not passed as an int, and using va_arg
to pull it out as an int is undefined behavior.  Well, the full story is even
worse; va_arg is defined by the C standard (not the C++ standard) and in
particular is defined in terms of "compatible" types.  C says that its enums
are compatible with some underlying (but unspecified) integral type, but
naturally C has nothing to say about scoped enumerations.  It would be
reasonable for C++ to specify that varargs calls apply the default argument
promotions to scoped enumerations also, but that's not how C++ is written
today.

The intent of scoped enums is that they never implicitly act like integers,
from which perspective it's good to require people to convert to the underlying
type if they must use varargs.


      parent reply	other threads:[~2013-10-13 14:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-58709-4@http.gcc.gnu.org/bugzilla/>
2013-10-13  0:19 ` ppluzhnikov at google dot com
2013-10-13  8:50 ` schwab@linux-m68k.org
2013-10-13 14:30 ` ppluzhnikov at google dot com [this message]

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-58709-4-ti5jOkR8Nd@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).