From 8bbd7c1d888701ad06d3bd5fbe0d8645b553133a Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 11 May 2023 09:39:41 -0700 Subject: [PATCH] Enable -Wextra in C++ builds (#1294) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1294 X-link: https://github.com/facebook/react-native/pull/37383 Add -Wextra to the build, and fixup some more instances of -Wunused-parameter that it sufaces which were not automatically fixable. Reviewed By: javache Differential Revision: D45772846 fbshipit-source-id: 680498f66f2104c29a71366bf30dba8895d9baf4 --- Yoga.podspec | 1 + benchmark/YGBenchmark.c | 5 +- cmake/project-defaults.cmake | 1 + java/jni/YGJNIVanilla.cpp | 117 ++++++++++++++++++----------------- java/jni/corefunctions.cpp | 1 + tests/EventsTest.cpp | 2 +- tests/util/TestUtil.cpp | 4 +- yoga/Yoga.cpp | 4 +- 8 files changed, 73 insertions(+), 62 deletions(-) diff --git a/Yoga.podspec b/Yoga.podspec index 957ee98e96..4ba88080f2 100644 --- a/Yoga.podspec +++ b/Yoga.podspec @@ -30,6 +30,7 @@ Pod::Spec.new do |spec| '-fexceptions', '-Wall', '-Werror', + '-Wextra', '-std=c++14', '-fPIC' ] diff --git a/benchmark/YGBenchmark.c b/benchmark/YGBenchmark.c index 771d51b6a1..ff1f664639 100644 --- a/benchmark/YGBenchmark.c +++ b/benchmark/YGBenchmark.c @@ -17,6 +17,8 @@ #define YGBENCHMARKS(BLOCK) \ int main(int argc, char const* argv[]) { \ + (void) argc; \ + (void) argv; \ clock_t __start; \ clock_t __endTimes[NUM_REPETITIONS]; \ { BLOCK } \ @@ -78,9 +80,10 @@ static YGSize _measure( YGMeasureMode widthMode, float height, YGMeasureMode heightMode) { + (void) node; return (YGSize){ .width = widthMode == YGMeasureModeUndefined ? 10 : width, - .height = heightMode == YGMeasureModeUndefined ? 10 : width, + .height = heightMode == YGMeasureModeUndefined ? 10 : height, }; } diff --git a/cmake/project-defaults.cmake b/cmake/project-defaults.cmake index 87f0e6b791..b6b37bccc1 100644 --- a/cmake/project-defaults.cmake +++ b/cmake/project-defaults.cmake @@ -33,6 +33,7 @@ add_compile_options( -fexceptions # Enable warnings and warnings as errors -Wall + -Wextra -Werror # Disable RTTI $<$:-fno-rtti> diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 5b7940b8f9..b054ae0c7c 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -424,73 +424,73 @@ static void jni_YGNodeCopyStyleJNI( _jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer)); } -#define YG_NODE_JNI_STYLE_PROP(javatype, type, name) \ - static javatype jni_YGNodeStyleGet##name##JNI( \ - JNIEnv* env, jobject obj, jlong nativePointer) { \ - return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \ +#define YG_NODE_JNI_STYLE_PROP(javatype, type, name) \ + static javatype jni_YGNodeStyleGet##name##JNI( \ + JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) { \ + return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \ + } \ + \ + static void jni_YGNodeStyleSet##name##JNI( \ + JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer, javatype value) { \ + YGNodeStyleSet##name( \ + _jlong2YGNodeRef(nativePointer), static_cast(value)); \ + } + +#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \ + static jlong jni_YGNodeStyleGet##name##JNI( \ + JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) { \ + return YogaValue::asJavaLong( \ + YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \ } \ \ static void jni_YGNodeStyleSet##name##JNI( \ - JNIEnv* env, jobject obj, jlong nativePointer, javatype value) { \ + JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer, jfloat value) { \ YGNodeStyleSet##name( \ - _jlong2YGNodeRef(nativePointer), static_cast(value)); \ - } - -#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \ - static jlong jni_YGNodeStyleGet##name##JNI( \ - JNIEnv* env, jobject obj, jlong nativePointer) { \ - return YogaValue::asJavaLong( \ - YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \ - } \ - \ - static void jni_YGNodeStyleSet##name##JNI( \ - JNIEnv* env, jobject obj, jlong nativePointer, jfloat value) { \ - YGNodeStyleSet##name( \ - _jlong2YGNodeRef(nativePointer), static_cast(value)); \ - } \ - \ - static void jni_YGNodeStyleSet##name##PercentJNI( \ - JNIEnv* env, jobject obj, jlong nativePointer, jfloat value) { \ - YGNodeStyleSet##name##Percent( \ - _jlong2YGNodeRef(nativePointer), static_cast(value)); \ + _jlong2YGNodeRef(nativePointer), static_cast(value)); \ + } \ + \ + static void jni_YGNodeStyleSet##name##PercentJNI( \ + JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer, jfloat value) { \ + YGNodeStyleSet##name##Percent( \ + _jlong2YGNodeRef(nativePointer), static_cast(value)); \ } #define YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(name) \ YG_NODE_JNI_STYLE_UNIT_PROP(name) \ static void jni_YGNodeStyleSet##name##AutoJNI( \ - JNIEnv* env, jobject obj, jlong nativePointer) { \ + JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) { \ YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \ } -#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \ - static jlong jni_YGNodeStyleGet##name##JNI( \ - JNIEnv* env, jobject obj, jlong nativePointer, jint edge) { \ - return YogaValue::asJavaLong(YGNodeStyleGet##name( \ - _jlong2YGNodeRef(nativePointer), static_cast(edge))); \ - } \ - \ - static void jni_YGNodeStyleSet##name##JNI( \ - JNIEnv* env, \ - jobject obj, \ - jlong nativePointer, \ - jint edge, \ - jfloat value) { \ - YGNodeStyleSet##name( \ - _jlong2YGNodeRef(nativePointer), \ - static_cast(edge), \ - static_cast(value)); \ - } \ - \ - static void jni_YGNodeStyleSet##name##PercentJNI( \ - JNIEnv* env, \ - jobject obj, \ - jlong nativePointer, \ - jint edge, \ - jfloat value) { \ - YGNodeStyleSet##name##Percent( \ - _jlong2YGNodeRef(nativePointer), \ - static_cast(edge), \ - static_cast(value)); \ +#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \ + static jlong jni_YGNodeStyleGet##name##JNI( \ + JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer, jint edge) { \ + return YogaValue::asJavaLong(YGNodeStyleGet##name( \ + _jlong2YGNodeRef(nativePointer), static_cast(edge))); \ + } \ + \ + static void jni_YGNodeStyleSet##name##JNI( \ + JNIEnv* /*env*/, \ + jobject /*obj*/, \ + jlong nativePointer, \ + jint edge, \ + jfloat value) { \ + YGNodeStyleSet##name( \ + _jlong2YGNodeRef(nativePointer), \ + static_cast(edge), \ + static_cast(value)); \ + } \ + \ + static void jni_YGNodeStyleSet##name##PercentJNI( \ + JNIEnv* /*env*/, \ + jobject /*obj*/, \ + jlong nativePointer, \ + jint edge, \ + jfloat value) { \ + YGNodeStyleSet##name##Percent( \ + _jlong2YGNodeRef(nativePointer), \ + static_cast(edge), \ + static_cast(value)); \ } YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction); @@ -712,12 +712,17 @@ static void jni_YGNodeSetHasBaselineFuncJNI( ->setBaselineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr); } -static void jni_YGNodePrintJNI(JNIEnv* env, jobject obj, jlong nativePointer) { +static void jni_YGNodePrintJNI( + JNIEnv* /*env*/, + jobject /*obj*/, + jlong nativePointer) { #ifdef DEBUG const YGNodeRef node = _jlong2YGNodeRef(nativePointer); YGNodePrint( node, (YGPrintOptions) (YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren)); +#else + (void) nativePointer; #endif } diff --git a/java/jni/corefunctions.cpp b/java/jni/corefunctions.cpp index 1f8c3f75c6..bbdcebd323 100644 --- a/java/jni/corefunctions.cpp +++ b/java/jni/corefunctions.cpp @@ -56,6 +56,7 @@ JNIEXPORT JNIEnv* getCurrentEnv() { } void logErrorMessageAndDie(const char* message) { + (void) message; VANILLAJNI_LOG_ERROR( "VanillaJni", "Aborting due to error detected in native code: %s", diff --git a/tests/EventsTest.cpp b/tests/EventsTest.cpp index 810fe53e27..78e7345962 100644 --- a/tests/EventsTest.cpp +++ b/tests/EventsTest.cpp @@ -290,7 +290,7 @@ EventArgs createArgs(const YGNode& node, const Event::Data data) { using Data = Event::TypedData; auto deleteData = [](void* x) { delete static_cast(x); }; - return {&node, E, {new Data{(data.get())}, deleteData}}; + return {&node, E, {new Data{(data.get())}, deleteData}, nullptr}; } template diff --git a/tests/util/TestUtil.cpp b/tests/util/TestUtil.cpp index 3b54f07ac7..ab7ff50496 100644 --- a/tests/util/TestUtil.cpp +++ b/tests/util/TestUtil.cpp @@ -19,9 +19,9 @@ int nodeInstanceCount = 0; namespace { void yogaEventSubscriber( - const YGNode& node, + const YGNode& /*node*/, Event::Type eventType, - const Event::Data& eventData) { + const Event::Data& /*eventData*/) { switch (eventType) { case Event::NodeAllocation: diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 1eccddbd0f..98fa7adbf0 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -42,8 +42,8 @@ static int YGDefaultLog( #ifdef ANDROID #include static int YGAndroidLog( - const YGConfigRef config, - const YGNodeRef node, + const YGConfigRef /*config*/, + const YGNodeRef /*node*/, YGLogLevel level, const char* format, va_list args) {