Skip to content

Commit 063c2b4

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Enable -Wpedantic for targets inside ReactCommon
Summary: React Native is compiled downstream with MSVC, meaning the introduction of code depending on language extensions specific to gcc/clang may cause breakage. We can enable `-Wpedantic` to flag any behavior not officially supported by the specified C++ standard. This will includes rules beyond what MSVC has trouble with, but seems to not have too many "noisy warnings". This change enables -Wpedantic in BUCK targets within ReactCommon. This makes the OSS C++ build for Android/iOS slightly more permissive than the internal build, A followup is to add the changes to OSS build logic as well, to avoid contributors seeing more errors upon internal submission. (checking with cortinico on how to do this for Android). react-native-windows uses a higher warning level than `-Wall`, which is an additional cause of compilation failures, but is not addressed as part of this change. Changelog: [Internal][Changed] - Enable -Wpedantic for targets inside ReactCommon Reviewed By: rshest Differential Revision: D38457812 fbshipit-source-id: 014da1ac0b7ad8f78154e6e447ed58def6bd0d47
1 parent 4699a39 commit 063c2b4

File tree

54 files changed

+108
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+108
-26
lines changed

React/Base/RCTAssert.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,18 @@ RCT_EXTERN NSString *RCTFormatStackTrace(NSArray<NSDictionary<NSString *, id> *>
159159
*/
160160
#if DEBUG
161161

162-
#define RCTAssertThread(thread, format...) \
162+
#define RCTAssertThread(thread, ...) \
163163
_Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") RCTAssert( \
164164
[(id)thread isKindOfClass:[NSString class]] ? [RCTCurrentThreadName() isEqualToString:(NSString *)thread] \
165165
: [(id)thread isKindOfClass:[NSThread class]] ? [NSThread currentThread] == (NSThread *)thread \
166166
: dispatch_get_current_queue() == (dispatch_queue_t)thread, \
167-
format); \
167+
__VA_ARGS__); \
168168
_Pragma("clang diagnostic pop")
169169

170170
#else
171171

172-
#define RCTAssertThread(thread, format...) \
173-
do { \
172+
#define RCTAssertThread(thread, ...) \
173+
do { \
174174
} while (0)
175175

176176
#endif

ReactAndroid/src/main/jni/react/jni/JCallback.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ class JCxxCallbackImpl : public jni::HybridClass<JCxxCallbackImpl, JCallback> {
3030
"Lcom/facebook/react/bridge/CxxCallbackImpl;";
3131

3232
static void registerNatives() {
33+
#if __clang__
34+
#pragma clang diagnostic push
35+
#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
36+
#endif
3337
javaClassStatic()->registerNatives({
3438
makeNativeMethod("nativeInvoke", JCxxCallbackImpl::invoke),
3539
});
40+
#if __clang__
41+
#pragma clang diagnostic pop
42+
#endif
3643
}
3744

3845
private:

ReactCommon/butter/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rn_xplat_cxx_library(
2929
],
3030
prefix = "butter",
3131
),
32+
compiler_flags_pedantic = True,
3233
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
3334
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
3435
force_static = True,

ReactCommon/callinvoker/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rn_xplat_cxx_library(
1010
],
1111
prefix = "ReactCommon",
1212
),
13+
compiler_flags_pedantic = True,
1314
labels = [
1415
"pfh:ReactNative_CommonInfrastructurePlaceholder",
1516
"supermodule:xplat/default/public.react_native.infra",

ReactCommon/cxxreact/BUCK

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rn_xplat_cxx_library(
1212
],
1313
prefix = "cxxreact",
1414
),
15+
compiler_flags_pedantic = True,
1516
fbobjc_compiler_flags = get_apple_compiler_flags(),
1617
force_static = True,
1718
labels = [
@@ -36,6 +37,7 @@ rn_xplat_cxx_library(
3637
[("", "JSBigString.h")],
3738
prefix = "cxxreact",
3839
),
40+
compiler_flags_pedantic = True,
3941
fbobjc_compiler_flags = get_apple_compiler_flags(),
4042
force_static = True,
4143
labels = [
@@ -60,6 +62,7 @@ rn_xplat_cxx_library(
6062
compiler_flags = [
6163
"-fno-omit-frame-pointer",
6264
],
65+
compiler_flags_pedantic = True,
6366
fbobjc_compiler_flags = get_apple_compiler_flags(),
6467
labels = [
6568
"pfh:ReactNative_CommonInfrastructurePlaceholder",
@@ -118,6 +121,7 @@ rn_xplat_cxx_library(
118121
)
119122
for header in CXXREACT_PUBLIC_HEADERS
120123
]),
124+
compiler_flags_pedantic = True,
121125
fbandroid_preprocessor_flags = get_android_inspector_flags(),
122126
fbobjc_compiler_flags = get_apple_compiler_flags(),
123127
fbobjc_force_static = True,

ReactCommon/cxxreact/JSBundleType.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,19 @@ enum struct ScriptTag {
3636
* bytes from a bundle in a way that gives access to that information.
3737
*/
3838
FOLLY_PACK_PUSH
39+
40+
struct FOLLY_PACK_ATTR Magic32 {
41+
uint32_t value;
42+
uint32_t reserved_;
43+
};
44+
3945
struct FOLLY_PACK_ATTR BundleHeader {
4046
BundleHeader() {
4147
std::memset(this, 0, sizeof(BundleHeader));
4248
}
4349

4450
union {
45-
struct {
46-
uint32_t value;
47-
uint32_t reserved_;
48-
} magic32;
51+
Magic32 magic32;
4952
uint64_t magic64;
5053
};
5154
uint32_t version;

ReactCommon/jsi/BUCK

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ rn_xplat_cxx_library(
1919
"-Wdelete-non-virtual-dtor",
2020
"-Wwrite-strings",
2121
],
22+
compiler_flags_pedantic = True,
2223
cxx_compiler_flags = [
2324
"-Wglobal-constructors",
2425
"-Wmissing-prototypes",
@@ -43,6 +44,7 @@ rn_xplat_cxx_library(
4344
exported_headers = [
4445
"jsi/JSIDynamic.h",
4546
],
47+
compiler_flags_pedantic = True,
4648
fbobjc_force_static = True,
4749
labels = [
4850
"pfh:ReactNative_CommonInfrastructurePlaceholder",
@@ -68,6 +70,7 @@ rn_xplat_cxx_library(
6870
"JSCRuntime.h",
6971
],
7072
apple_sdks = (IOS, MACOSX),
73+
compiler_flags_pedantic = True,
7174
fbobjc_compiler_flags = [
7275
"-Os",
7376
],

ReactCommon/jsinspector/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ rn_xplat_cxx_library(
2626
],
2727
prefix = "jsinspector",
2828
),
29+
compiler_flags_pedantic = True,
2930
fbandroid_preferred_linkage = "shared",
3031
labels = [
3132
"pfh:ReactNative_CommonInfrastructurePlaceholder",

ReactCommon/logger/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ rn_xplat_cxx_library(
2626
],
2727
prefix = "logger",
2828
),
29+
compiler_flags_pedantic = True,
2930
fbandroid_preferred_linkage = "shared",
3031
labels = [
3132
"pfh:ReactNative_CommonInfrastructurePlaceholder",

ReactCommon/react/bridging/BUCK

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ rn_xplat_cxx_library(
77
exported_headers = glob(["*.h"]),
88
compiler_flags_enable_exceptions = True,
99
compiler_flags_enable_rtti = True,
10+
compiler_flags_pedantic = True,
1011
labels = [
1112
"pfh:ReactNative_CommonInfrastructurePlaceholder",
1213
"supermodule:xplat/default/public.react_native.infra",
@@ -28,6 +29,7 @@ rn_xplat_cxx_library(
2829
name = "testlib",
2930
header_namespace = "react/bridging",
3031
exported_headers = glob(["tests/*.h"]),
32+
compiler_flags_pedantic = True,
3133
platforms = (ANDROID, APPLE, CXX),
3234
visibility = ["PUBLIC"],
3335
exported_deps = [

0 commit comments

Comments
 (0)