public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58709] [c++11] Bogus? int vs. scoped enum printf warning when -fabi-version >= 6
       [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
  2 siblings, 0 replies; 3+ messages in thread
From: ppluzhnikov at google dot com @ 2013-10-13  0:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
(In reply to Andrew Pinski from comment #1)
> I think the warning is correct as it is not promoted to int in the function
> call.

How is it passed then?

I see:

        movl    $0, 4(%esp)
        movl    $.LC0, (%esp)
        call    printf

on ix86, and

        movl    $0, %esi
        movl    $.LC0, %edi
        call    printf

on x86_64. Looks like an "int" to me.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/58709] [c++11] Bogus? int vs. scoped enum printf warning when -fabi-version >= 6
       [not found] <bug-58709-4@http.gcc.gnu.org/bugzilla/>
  2013-10-13  0:19 ` [Bug c++/58709] [c++11] Bogus? int vs. scoped enum printf warning when -fabi-version >= 6 ppluzhnikov at google dot com
@ 2013-10-13  8:50 ` schwab@linux-m68k.org
  2013-10-13 14:30 ` ppluzhnikov at google dot com
  2 siblings, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2013-10-13  8:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andreas Schwab <schwab@linux-m68k.org> ---
The warning is target independent and only depends on the type.  You get the
same warning for int vs long even if they are the same size.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/58709] [c++11] Bogus? int vs. scoped enum printf warning when -fabi-version >= 6
       [not found] <bug-58709-4@http.gcc.gnu.org/bugzilla/>
  2013-10-13  0:19 ` [Bug c++/58709] [c++11] Bogus? int vs. scoped enum printf warning when -fabi-version >= 6 ppluzhnikov at google dot com
  2013-10-13  8:50 ` schwab@linux-m68k.org
@ 2013-10-13 14:30 ` ppluzhnikov at google dot com
  2 siblings, 0 replies; 3+ messages in thread
From: ppluzhnikov at google dot com @ 2013-10-13 14:30 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-13 14:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-58709-4@http.gcc.gnu.org/bugzilla/>
2013-10-13  0:19 ` [Bug c++/58709] [c++11] Bogus? int vs. scoped enum printf warning when -fabi-version >= 6 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 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).