-
Notifications
You must be signed in to change notification settings - Fork 173
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
Fix compiler warnings with MacOS Clang 14.0.3 #6467
Conversation
Why introduce this project wide? It's pretty useful, why not to fix warnings? There are not that many of them |
There are some of these warnings in the 3rd party catch and generated/parser source as well - I can fix the couple of warnings in the regular source. |
Well it's fine to set flags for external dependencies, but would be good to keep our codebase clean at least. |
CMakeLists.txt
Outdated
@@ -57,6 +57,17 @@ function(add_cxx_flag_if_supported flag) | |||
endif() | |||
endfunction() | |||
|
|||
function(check_if_cxx_compiler_flag_supported flag out_var) | |||
if(flag MATCHES "^-Wno-") | |||
# Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're assuming unrecognized -Wno flags will be ignored can't we just set -Wno-unused-but-set-variable unconditionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had originally just disabled it for the project, but I got some push back, so I disabled it just for the 3rd party items. I guess it is a valid warning, similar to the -Wunused-variable
warning that is already enabled. There were only 2 places where this warning was found in core, but they were also found in Catch2 and the flex generated parser cpp file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh - I misread your comment. I think this was there to avoid a false positive to determine if a no-
flag was really supported or not by the compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If passing -Wno to the compiler doesn't result in an error we don't really care if it's actually doing anything or not, so doing complicated things to try to check if it's actually disabling a warning seems pointless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point and I can change it if you prefer, but I copied this function wholesale from this commit: ca39b9f and it also matches the existing add_cxx_flag_if_supported
function already in the same CMakeLists.txt file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC unrecognized -Wno-blah flags aren't exactly ignored. There are in a weird Schrödinger state where they act as-if ignored unless the compiler prints anything else, in which case it also prints a warning about an unrecognized flag. This can be annoying if you pass tons of -Wno-blah flags unconditionally. Note that we are already doing something like this:
Lines 46 to 58 in 063927d
function(add_cxx_flag_if_supported flag) | |
if(flag MATCHES "^-Wno-") | |
# Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead. | |
string(REPLACE "-Wno-" "-W" check_flag ${flag}) | |
else() | |
set(check_flag ${flag}) | |
endif() | |
check_cxx_compiler_flag(${check_flag} HAVE${check_flag}) | |
if(HAVE${check_flag}) | |
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:${flag}>) | |
endif() | |
endfunction() |
I added that logic based on this code from the mongo build scripts.
We should probably dedupe this logic between the functions though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I remember running into that before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change add_cxx_flag_if_supported
to use check_if_cxx_flag_is_supported
rather than duplicating the logic.
CMakeLists.txt
Outdated
@@ -112,6 +123,8 @@ else() | |||
# compilers that we still support. It is also harmless, unlike pessimizing moves. | |||
add_cxx_flag_if_supported(-Wno-redundant-move) | |||
|
|||
check_if_cxx_compiler_flag_supported(-Wno-unused-but-set-variable HAS-Wno-unused-but-set-variable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the output is only used in one place, I think I'd move this there.
FYI - The Jenkins failure is due to the results file not being exported successfully from the iOSSimulator, even though all the tests passed. This happens occasionally and we have an existing task to look into this. |
CMakeLists.txt
Outdated
# Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead. | ||
string(REPLACE "-Wno-" "-W" check_flag ${flag}) | ||
function(append_source_file_compile_options file property) | ||
get_source_file_property(SRC_PROPS_${file} ${file} COMPILE_OPTIONS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_source_file_property(SRC_PROPS_${file} ${file} COMPILE_OPTIONS) | |
get_source_file_property(OLD_OPTS ${file} COMPILE_OPTIONS) |
Because you are in a function, you don't need to use a unique variable name.
CMakeLists.txt
Outdated
string(REPLACE "-Wno-" "-W" check_flag ${flag}) | ||
function(append_source_file_compile_options file property) | ||
get_source_file_property(SRC_PROPS_${file} ${file} COMPILE_OPTIONS) | ||
if ("${SRC_PROPS_${file}}" STREQUAL "NOTFOUND" OR "${SRC_PROPS_${file}}" STREQUAL "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ("${SRC_PROPS_${file}}" STREQUAL "NOTFOUND" OR "${SRC_PROPS_${file}}" STREQUAL "") | |
if (NOT OLD_OPTS) |
The if()
command in cmake is wierd and magical but somehow works out well with the rest of cmake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Created #6474 to address the data race failure in |
What, How & Why?
MacOS Clang 14.0.3 enables
-Wunqualified-std-cast-call
and-Wunused-but-set-variable
warnings. Fix the unqualifiedmove
's and existing unused-but-set-variable warnings in the Realm Core source. The warning is disabled only for the bison and flex generated parser files and the Catch2 library.Updated
☑️ ToDos
[ ] 🚦 Tests (or not relevant)[ ] C-API, if public C++ API changed.