Skip to content

Commit

Permalink
Enable -Wextra in C++ builds (#1294)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1294

X-link: facebook/react-native#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
  • Loading branch information
NickGerleman authored and facebook-github-bot committed May 11, 2023
1 parent 86d3ac0 commit 8bbd7c1
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 62 deletions.
1 change: 1 addition & 0 deletions Yoga.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Pod::Spec.new do |spec|
'-fexceptions',
'-Wall',
'-Werror',
'-Wextra',
'-std=c++14',
'-fPIC'
]
Expand Down
5 changes: 4 additions & 1 deletion benchmark/YGBenchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 } \
Expand Down Expand Up @@ -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,
};
}

Expand Down
1 change: 1 addition & 0 deletions cmake/project-defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_compile_options(
-fexceptions
# Enable warnings and warnings as errors
-Wall
-Wextra
-Werror
# Disable RTTI
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
Expand Down
117 changes: 61 additions & 56 deletions java/jni/YGJNIVanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<type>(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<type>(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<float>(value)); \
} \
\
static void jni_YGNodeStyleSet##name##PercentJNI( \
JNIEnv* env, jobject obj, jlong nativePointer, jfloat value) { \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
} \
\
static void jni_YGNodeStyleSet##name##PercentJNI( \
JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer, jfloat value) { \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), static_cast<float>(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<YGEdge>(edge))); \
} \
\
static void jni_YGNodeStyleSet##name##JNI( \
JNIEnv* env, \
jobject obj, \
jlong nativePointer, \
jint edge, \
jfloat value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<float>(value)); \
} \
\
static void jni_YGNodeStyleSet##name##PercentJNI( \
JNIEnv* env, \
jobject obj, \
jlong nativePointer, \
jint edge, \
jfloat value) { \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<float>(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<YGEdge>(edge))); \
} \
\
static void jni_YGNodeStyleSet##name##JNI( \
JNIEnv* /*env*/, \
jobject /*obj*/, \
jlong nativePointer, \
jint edge, \
jfloat value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<float>(value)); \
} \
\
static void jni_YGNodeStyleSet##name##PercentJNI( \
JNIEnv* /*env*/, \
jobject /*obj*/, \
jlong nativePointer, \
jint edge, \
jfloat value) { \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<float>(value)); \
}

YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction);
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions java/jni/corefunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/EventsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ EventArgs createArgs(const YGNode& node, const Event::Data data) {
using Data = Event::TypedData<E>;
auto deleteData = [](void* x) { delete static_cast<Data*>(x); };

return {&node, E, {new Data{(data.get<E>())}, deleteData}};
return {&node, E, {new Data{(data.get<E>())}, deleteData}, nullptr};
}

template <Event::Type E>
Expand Down
4 changes: 2 additions & 2 deletions tests/util/TestUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ static int YGDefaultLog(
#ifdef ANDROID
#include <android/log.h>
static int YGAndroidLog(
const YGConfigRef config,
const YGNodeRef node,
const YGConfigRef /*config*/,
const YGNodeRef /*node*/,
YGLogLevel level,
const char* format,
va_list args) {
Expand Down

0 comments on commit 8bbd7c1

Please sign in to comment.