-
Notifications
You must be signed in to change notification settings - Fork 28
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
Improve C++ standard compliance and reduce pedantic warnings #218
Comments
I fixed errors and warnings until 4fcaeca, but it still remain others. Some of them don't seem to be warned on Windows. I'll try compiling on other OS if I have the opportunity. |
Here's a patch to add the warning & pedantic compiler flags (MSVC ones untested, but I read that they might work?) to the project file + fix a pedantic error to make it compile. I've marked the error degradations via a separate line. Compilation succeeds on Linux + hardening w/ GCC, I've attached a build log below that contains the remaining problems that require those diff --git a/BambooTracker/BambooTracker.pro b/BambooTracker/BambooTracker.pro
index 76d0e82..00a4504 100644
--- a/BambooTracker/BambooTracker.pro
+++ b/BambooTracker/BambooTracker.pro
@@ -40,7 +40,21 @@ else {
CONFIG += c++14
-msvc:QMAKE_CXXFLAGS += /source-charset:utf-8
+# C/C++ compiler flags
+msvc {
+ CPPFLAGS += /Wall /Wp64 /WX
+ CPPFLAGS += /source-charset:utf-8
+}
+else:if(gcc|clang) {
+ CPPFLAGS += -Wall -Wextra -Werror -pedantic -pedantic-errors
+ # Temporary known-error downgrades
+ CPPFLAGS += -Wno-error=vla -Wno-error=stringop-truncation -Wno-error=deprecated-declarations
+}
+else {
+ message("Unknown compiler, won't attempt to add warning & pedantic compiler switches.")
+}
+QMAKE_CFLAGS += $$CPPFLAGS
+QMAKE_CXXFLAGS += $$CPPFLAGS
SOURCES += \
chips/c86ctl/c86ctl_wrapper.cpp \
diff --git a/BambooTracker/stream/RtAudio/RtAudio.cpp b/BambooTracker/stream/RtAudio/RtAudio.cpp
index c16566c..a805c0b 100644
--- a/BambooTracker/stream/RtAudio/RtAudio.cpp
+++ b/BambooTracker/stream/RtAudio/RtAudio.cpp
@@ -2018,7 +2018,7 @@ struct JackHandle {
};
#if !defined(__RTAUDIO_DEBUG__)
-static void jackSilentError( const char * ) {};
+static void jackSilentError( const char * ) {}
#endif
RtApiJack :: RtApiJack() Full build log. (Building part starts on line 364) |
In MSVC, /WX generates some errors below:
C2220 is only appeared when the and also happened link error on RtAudio with MSVC, it needs to insert win32 {
greaterThan(QT_MAJOR_VERSION, 4):greaterThan(QT_MINOR_VERSION, 5) {
DEFINES += __WINDOWS_WASAPI__
LIBS += -lole32 -lwinmm -lksuser -lmfplat -lmfuuid -lwmcodecdspuuid
}
DEFINES += __WINDOWS_DS__
LIBS += -lole32 -lwinmm -ldsound -luser32 # Modified
} After fixing these, it works well on my emvironment. I'll fix and commit. I checked your build log,
Is this warning avoidable to replace vla with else {
void *bufs = new void*[channels];
size_t offset = stream_.bufferSize * formatBytes( format );
for ( int i=0; i<channels; i++ )
bufs[i] = (void *) (buffer + (i * offset));
result = snd_pcm_readn( handle[1], bufs, stream_.bufferSize );
delete[] bufs;
} |
That is intentional, to point out code problems right away instead of hiding them in the build log. The
I think this is the right way to tackle this issue: Make everything an issue, see where we crash and fix the problem / mask it if it's out of our reach (like system headers, see commit below). Would you prefer removing that from the other compiler setting as well?
It is avoidable with
OPNA2608@d534a18 is a commit to BambooTracker.pro and the RtMidi/RtAudio files that patches those warnings and adds more sophisticated switch appending via (on Clang slightly hacky) compiler version detection. It should fix the current build issues on this repo's CI. Additionally, I made sure that it also works with the CI targets that would be added in #200.
Locally built binary works fine with these changes, but I'm no C++ guru and it was quickly hacked together so you should prolly take a closer look at it first. |
I checked your commit and it seems works well as far as I can see. |
I also think you should fix all errors as you say. |
Would you like me to open a PR with the leftover changes from that commit? |
This is incorrect translation, "I also think we should fix all errors as you say", not only you. I'm sorry to make many mistakes.
If possible, I would like you to do. Especially your .pro compilation conditions are more better than mine. Also, merging your PR will record your many contributions and efforts in |
With the PR merged, I see the following leftover problems/questions:
|
Related to #216.
BambooTracker has some snippets of code that a compiler set to be very pedantic about standard compliance and good practices will quickly point out and error on. I thought that a meta-issue about fixing them and how to ensure a compliant codebase in the future would be useful.
Some of those problems stem from included projects, I decided to point them out regardless. We could fix them only for ourselves / submit any changes upstream or ignore them for the unforeseeable future.
How to verify the problems (or: how to get your compiler to nag about compliance and bad practices):
On GCC/MinGW and Clang:
qmake (the usual options here) QMAKE_CXXFLAGS+="-Wall -Wextra -Werror -pedantic -pedantic-errors (+ whatever exceptions are required to compile, ideally none)"
Or set the
QMAKE_CXXFLAGS
setting inBambooTracker/BambooTracker.pro
I had to set the same setting inBambooTracker/stream/RtAudio/RtAudio.pri
andBambooTracker/midi/RtMidi/RtMidi.pri
for it to work.(If you know a better way of setting this, please let me know!)
MSVC appears to have no flag to enable pedantic checking, but it has some variations of
/W…
ones to enable extra warnings and mark warnings as errors.Currently needed exceptions required to compile successfully after some easy fixes (tested on Linux, GCC & Clang):
(Prefix to disable a specific warning is
-Wno-error=
)unused-parameter
(low priority)BambooTracker/chips/c86ctl/c86ctl_wrapper.cpp
- several methodsdeprecated-declarations
(Clang-only, low prioriy)BambooTracker/midi/RtMidi/RtMidi.cpp, several methods -
'(method declaration)' is deprecated`redundant-move
(Clang-only)BambooTracker/instrument/instrument.cpp
, several methods -redundant move in return statement
type-limits
BambooTracker/chips/codec/ymb_codec.hpp
, line 14 -comparison of unsigned expression < 0 is always false
maybe-uninitialized
BambooTracker/playback.cpp
line 336 -»storeEffectToMap.bool (PlaybackManager::*)(int, Effect)::__pfn« may be uninitialised
BambooTracker/command/pattern/set_effect_value_to_step_command.cpp
, line 35 -'value' may be used uninitialized in this function
vla
BambooTracker/streams/RtAudio/RtAudio.cpp
, line 8279 & 8349 -ISO C++ forbids variable length array 'bufs'
Easy fixes:
(No warranty for any of these being the correct way to resolve the issues.)
Excessive
;
ininstrument_selection_dialog.hpp
.Enumeral and non-enumeral type in conditional expression in
pattern_editor_panel.cpp
.Comparison of integer expressions of different signedness in
command_sequence.cpp
:ISO C++ prohibits anonymous structs in
bank.cpp
: (you probably want to replacevals_type
andvals
in this with something proper)What else?
There are some more warnings, even with all error settings turned up to 100.
BambooTracker/chips/mame/ymdeltat.c
, line 221 -left-hand operand of comma expression has no effect
unused-value
onesEnsuring future compliance
That's where I'm abit lost. The flags aren't compatible across compilers, mostly due to MSVC. I'm thinking if we could detect the compiler & add code to the project file to add the appropriate flags, don't have much time to investigate it right now either.
The text was updated successfully, but these errors were encountered: