Enable compiler warnings for Android

This commit is contained in:
Chris Thrasher 2022-08-06 22:13:40 -06:00 committed by Vittorio Romeo
parent a71d60a0c9
commit 142ccf57bd
3 changed files with 13 additions and 23 deletions

View File

@ -36,23 +36,6 @@ function(set_target_warnings target)
/wd4800 # disable warnings regarding implicit conversions to bool
)
# some warnings are not supported on older NDK versions used for CI
if (ANDROID)
set(NON_ANDROID_CLANG_AND_GCC_WARNINGS "")
set(NON_ANDROID_GCC_WARNINGS "")
else()
set(NON_ANDROID_CLANG_AND_GCC_WARNINGS
-Wnull-dereference # warn if a null dereference is detected
-Wold-style-cast # warn for c-style casts
-Wpedantic # warn if non-standard C++ is used
)
set(NON_ANDROID_GCC_WARNINGS
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
-Wduplicated-cond # warn if if / else chain has duplicated conditions
)
endif()
set(CLANG_AND_GCC_WARNINGS
-Wall
-Wextra # reasonable and standard
@ -67,9 +50,15 @@ function(set_target_warnings target)
-Wformat=2 # warn on security issues around functions that format output (ie printf)
-Wimplicit-fallthrough # warn when a missing break causes control flow to continue at the next case in a switch statement
-Wsuggest-override # warn when 'override' could be used on a member function overriding a virtual function
${NON_ANDROID_CLANG_AND_GCC_WARNINGS}
-Wnull-dereference # warn if a null dereference is detected
-Wold-style-cast # warn for c-style casts
-Wpedantic # warn if non-standard C++ is used
)
if(ANDROID)
set(CLANG_AND_GCC_WARNINGS ${CLANG_AND_GCC_WARNINGS} -Wno-main) # allow main() to be called
endif()
if(WARNINGS_AS_ERRORS)
set(CLANG_AND_GCC_WARNINGS ${CLANG_AND_GCC_WARNINGS} -Werror)
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
@ -82,7 +71,8 @@ function(set_target_warnings target)
set(GCC_WARNINGS
${CLANG_AND_GCC_WARNINGS}
${NON_ANDROID_GCC_WARNINGS}
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
-Wduplicated-cond # warn if if / else chain has duplicated conditions
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
# -Wuseless-cast # warn if you perform a cast to the same type (disabled because it is not portable as some type aliases might vary between platforms)
)

View File

@ -88,7 +88,7 @@ ActivityStates* retrieveStates(ANativeActivity* activity)
assert(activity != nullptr);
// Hide the ugly cast we find in each callback function
return (ActivityStates*)activity->instance;
return static_cast<ActivityStates*>(activity->instance);
}

View File

@ -61,7 +61,7 @@ const char* getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
// Get the value of meta-data named "sfml.app.lib_name"
jclass classBundle = lJNIEnv->FindClass("android/os/Bundle");
jmethodID methodGetString = lJNIEnv->GetMethodID(classBundle, "getString", "(Ljava/lang/String;)Ljava/lang/String;");
jstring valueString = (jstring)lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName);
jstring valueString = static_cast<jstring>(lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName));
// No meta-data "sfml.app.lib_name" was found so we abort and inform the user
if (valueString == nullptr)
@ -211,8 +211,8 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
void* handle = loadLibrary(getLibraryName(lJNIEnv, ObjectActivityInfo), lJNIEnv, ObjectActivityInfo);
// Call the original ANativeActivity_onCreate function
activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle,
"ANativeActivity_onCreate");
activityOnCreatePointer ANativeActivity_onCreate = reinterpret_cast<activityOnCreatePointer>(
dlsym(handle, "ANativeActivity_onCreate"));
if (!ANativeActivity_onCreate)
{