Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation errors: narrowing conversion in binhack.hpp #6

Open
hackerb9 opened this issue Oct 10, 2019 · 1 comment
Open

Compilation errors: narrowing conversion in binhack.hpp #6

hackerb9 opened this issue Oct 10, 2019 · 1 comment

Comments

@hackerb9
Copy link

When cd'ing to src and running make on a system running Debian 10 (stable), the compilation dies with error messages that look like this:

make[2]: Entering directory '/tmp/mksdiso/src/binhack'
g++ -O3 -fPIC -c src/binhack.cpp -o obj/binhack.o
In file included from src/binhack.cpp:1:
src/binhack.hpp:772:1: error: narrowing conversion of ‘160’ from ‘int’ to ‘char’ inside { } [-Wnarrowing]
 };
 ^
src/binhack.hpp:772:1: error: narrowing conversion of ‘160’ from ‘int’ to ‘char’ inside { } [-Wnarrowing]
src/binhack.hpp:772:1: error: narrowing conversion of ‘160’ from ‘int’ to ‘char’ inside { } [-Wnarrowing]
src/binhack.hpp:772:1: error: narrowing conversion of ‘160’ from ‘int’ to ‘char’ inside { } [-Wnarrowing]

The problem appears to be that the literal constants (0xA0) are not specified to be of type char, and the C++ 11 standard states that such code is "not well formed".

Here's what the manpage for gcc has to say.

-Wno-narrowing (C++ and Objective-C++ only)
   
    For C++11 and later standards, narrowing conversions are diagnosed by
    default, as required by the standard. A narrowing conversion from a
    constant produces an error, and a narrowing conversion from a non-constant
    produces a warning, but -Wno-narrowing suppresses the diagnostic. Note that
    this does not affect the meaning of well-formed code; narrowing conversions
    are still considered ill-formed in SFINAE contexts.

    With -Wnarrowing in C++98, warn when a narrowing conversion prohibited by
    C++11 occurs within ‘{ }’, e.g.

    int i = { 2.2 }; // error: narrowing from double to int

    This flag is included in -Wall and -Wc++11-compat.
@hackerb9
Copy link
Author

By the way, running

CPPFLAGS=-Wno-narrowing make

worked around the problem once I had modified the makefiles to not clobber CPPFLAGS. (Should use CPPFLAGS += ... instead of CPPFLAGS = ....)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant