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

error: non-constant-expression cannot be narrowed from type 'int' to 'uint8_t' #7

Closed
yurivict opened this issue Feb 2, 2019 · 3 comments

Comments

@yurivict
Copy link

yurivict commented Feb 2, 2019

clang-60 prints these errors:

In file included from ../../dpf/distrho/DistrhoUIMain.cpp:24:
../../dpf/distrho/src/DistrhoUIDSSI.cpp:197:13: error: non-constant-expression cannot be narrowed from type 'int' to 'uint8_t' (aka 'unsigned char') in initializer list
      [-Wc++11-narrowing]
            channel + (velocity != 0 ? 0x90 : 0x80),
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../dpf/distrho/src/DistrhoUIDSSI.cpp:197:13: note: insert an explicit cast to silence this issue
            channel + (velocity != 0 ? 0x90 : 0x80),
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            static_cast<uint8_t>(                  )
@yurivict
Copy link
Author

yurivict commented Feb 2, 2019

gcc also prints warnings:

In file included from ../../dpf/distrho/DistrhoUIMain.cpp:24:0:
../../dpf/distrho/src/DistrhoUIDSSI.cpp: In member function 'void DISTRHO::UIDssi::sendNote(uint8_t, uint8_t, uint8_t)':
../../dpf/distrho/src/DistrhoUIDSSI.cpp:197:21: warning: narrowing conversion of '(((int)channel) + ((((int)velocity) != 0) ? 144 : 128))' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]
             channel + (velocity != 0 ? 0x90 : 0x80),
             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@falkTX
Copy link
Contributor

falkTX commented Feb 3, 2019

You can build with -std=c++98 to get rid of these warnings I guess.

A simple static cast should do it.
Patches welcome :)

@falkTX
Copy link
Contributor

falkTX commented Oct 30, 2022

dont know exactly when this was fixed, but latest dpf doesnt have this warning any more.

@falkTX falkTX closed this as completed Oct 30, 2022
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

2 participants