[Bug c++/54076] New: wrong/misleading warning with -Wsign-promo and enums with underlying type

plasmahh at gmx dot net gcc-bugzilla@gcc.gnu.org
Tue Jul 24 08:49:00 GMT 2012


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

             Bug #: 54076
           Summary: wrong/misleading warning with -Wsign-promo and enums
                    with underlying type
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: plasmahh@gmx.net


When compiling with -Wsign-promo

#include <cstddef>
void vs( const char*, long ) { }
void vs( const char*, size_t ) { }

template<size_t H, size_t L>
struct dt
{
        enum : size_t { h = H };
        enum : size_t { l = L };
};

int main(int  /*argc*/, const char * /*argv*/[])
{
        typedef dt<3,4> d_t;
        const char* x = "Hello World";
        vs(x+d_t::h,d_t::l);
}

I get the warning:

promo.cxx: In function 'int main(int, const char**)':
promo.cxx:16:20: warning: passing 'dt<3ul, 4ul>::<anonymous enum>' chooses
'size_t {aka long unsigned int}' over 'long int' [-Wsign-promo]
  vs(x+d_t::h,d_t::l);
                    ^
promo.cxx:16:20: warning:   in call to 'void vs(const char*, size_t)'
[-Wsign-promo]


>From the manpage of gcc it says for -Wsign-promo :

Warn when overload resolution chooses a promotion from unsigned or enumerated
type to a signed type, over a conversion to an unsigned type of the same size.
Previous versions of G++ would try to preserve unsignedness, but the standard
mandates the current behavior.


First of all, intuitively I would not at all expect such a warning, since the
underlying type is set, the enum should behave like that underlying type for
overload resoltion (I would think 4.5-4 applies here).

Secondly the description says that it warns for "[...]a promotion from unsigned
or enumerated type to a signed type, over a conversion to an unsigned
type[...]" and here it did not chose to promote to a signed type. If the
warning was intentional, then its documentation is misleading.



More information about the Gcc-bugs mailing list