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

            Bug ID: 62096
           Summary: unexpected warning overflow in implicit constant
                    conversion
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: travis.vitek at roguewave dot com

The following test case generates a an unexpected warning.

[vitek@sidewinder] 350 % gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/amd/packages/mdx/redhat/compilers/gcc-4.9.0/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.9.0/configure --prefix=/build/gcc-4.9.0
--enable-languages=c,c++
Thread model: posix
gcc version 4.9.0 (GCC)
[vitek@sidewinder] 351 % cat t.cpp
enum E {
    E_val  = 1,
};

inline constexpr E operator~(E e)
{
    return E(~static_cast<int>(e));
}

int main()
{
    int val = ~E_val;
    (void) val;
}
[vitek@sidewinder] 352 % g++ --pedantic -std=c++11 -c ./t.cpp
./t.cpp: In function 'int main()':
./t.cpp:12:16: warning: overflow in implicit constant conversion [-Woverflow]
     int val = ~E_val;
                ^
[vitek@sidewinder] 353 %


The issue seems to be related to the function being constexpr and the type of
the destination being int. If I remove the constexpr or change the destination
type (to long long or E), the warning goes away.

Reply via email to