Skip to content

Commit 04e3aa2

Browse files
committed
src: introduce USE() for silencing compiler warnings
PR-URL: #17333 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent a012672 commit 04e3aa2

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/async_wrap.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) {
169169
Local<Value> async_id_value = Number::New(env->isolate(), async_id);
170170
Local<Function> fn = env->async_hooks_promise_resolve_function();
171171
FatalTryCatch try_catch(env);
172-
fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value)
173-
.FromMaybe(Local<Value>());
172+
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
174173
}
175174

176175

@@ -198,8 +197,7 @@ void AsyncWrap::EmitBefore(Environment* env, double async_id) {
198197
Local<Value> async_id_value = Number::New(env->isolate(), async_id);
199198
Local<Function> fn = env->async_hooks_before_function();
200199
FatalTryCatch try_catch(env);
201-
fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value)
202-
.FromMaybe(Local<Value>());
200+
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
203201
}
204202

205203

@@ -229,8 +227,7 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) {
229227
Local<Value> async_id_value = Number::New(env->isolate(), async_id);
230228
Local<Function> fn = env->async_hooks_after_function();
231229
FatalTryCatch try_catch(env);
232-
fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value)
233-
.FromMaybe(Local<Value>());
230+
USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value));
234231
}
235232

236233
class PromiseWrap : public AsyncWrap {
@@ -731,8 +728,7 @@ void AsyncWrap::EmitAsyncInit(Environment* env,
731728
};
732729

733730
FatalTryCatch try_catch(env);
734-
init_fn->Call(env->context(), object, arraysize(argv), argv)
735-
.FromMaybe(Local<Value>());
731+
USE(init_fn->Call(env->context(), object, arraysize(argv), argv));
736732
}
737733

738734

src/node_crypto.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18201820
String::NewFromUtf8(env->isolate(), mem->data,
18211821
String::kNormalString, mem->length));
18221822
}
1823-
(void) BIO_reset(bio);
1823+
USE(BIO_reset(bio));
18241824

18251825
X509_NAME* issuer_name = X509_get_issuer_name(cert);
18261826
if (X509_NAME_print_ex(bio, issuer_name, 0, X509_NAME_FLAGS) > 0) {
@@ -1829,7 +1829,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18291829
String::NewFromUtf8(env->isolate(), mem->data,
18301830
String::kNormalString, mem->length));
18311831
}
1832-
(void) BIO_reset(bio);
1832+
USE(BIO_reset(bio));
18331833

18341834
int nids[] = { NID_subject_alt_name, NID_info_access };
18351835
Local<String> keys[] = { env->subjectaltname_string(),
@@ -1856,7 +1856,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18561856
String::NewFromUtf8(env->isolate(), mem->data,
18571857
String::kNormalString, mem->length));
18581858

1859-
(void) BIO_reset(bio);
1859+
USE(BIO_reset(bio));
18601860
}
18611861

18621862
EVP_PKEY* pkey = X509_get_pubkey(cert);
@@ -1873,7 +1873,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18731873
info->Set(env->modulus_string(),
18741874
String::NewFromUtf8(env->isolate(), mem->data,
18751875
String::kNormalString, mem->length));
1876-
(void) BIO_reset(bio);
1876+
USE(BIO_reset(bio));
18771877

18781878
uint64_t exponent_word = static_cast<uint64_t>(BN_get_word(e));
18791879
uint32_t lo = static_cast<uint32_t>(exponent_word);
@@ -1887,7 +1887,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
18871887
info->Set(env->exponent_string(),
18881888
String::NewFromUtf8(env->isolate(), mem->data,
18891889
String::kNormalString, mem->length));
1890-
(void) BIO_reset(bio);
1890+
USE(BIO_reset(bio));
18911891
}
18921892

18931893
if (pkey != nullptr) {
@@ -1904,7 +1904,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
19041904
info->Set(env->valid_from_string(),
19051905
String::NewFromUtf8(env->isolate(), mem->data,
19061906
String::kNormalString, mem->length));
1907-
(void) BIO_reset(bio);
1907+
USE(BIO_reset(bio));
19081908

19091909
ASN1_TIME_print(bio, X509_get_notAfter(cert));
19101910
BIO_get_mem_ptr(bio, &mem);
@@ -2882,7 +2882,7 @@ int Connection::HandleBIOError(BIO *bio, const char* func, int rv) {
28822882
return rv;
28832883

28842884
int retry = BIO_should_retry(bio);
2885-
(void) retry; // unused if !defined(SSL_PRINT_DEBUG)
2885+
USE(retry); // unused if !defined(SSL_PRINT_DEBUG)
28862886

28872887
if (BIO_should_write(bio)) {
28882888
DEBUG_PRINT("[%p] BIO: %s want write. should retry %d\n",
@@ -5358,7 +5358,7 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
53585358
EC_KEY_set_public_key(ecdh->key_, nullptr);
53595359

53605360
MarkPopErrorOnReturn mark_pop_error_on_return;
5361-
(void) &mark_pop_error_on_return; // Silence compiler warning.
5361+
USE(&mark_pop_error_on_return);
53625362

53635363
const BIGNUM* priv_key = EC_KEY_get0_private_key(ecdh->key_);
53645364
CHECK_NE(priv_key, nullptr);
@@ -5421,7 +5421,7 @@ bool ECDH::IsKeyValidForCurve(const BIGNUM* private_key) {
54215421

54225422
bool ECDH::IsKeyPairValid() {
54235423
MarkPopErrorOnReturn mark_pop_error_on_return;
5424-
(void) &mark_pop_error_on_return; // Silence compiler warning.
5424+
USE(&mark_pop_error_on_return);
54255425
return 1 == EC_KEY_check_key(key_);
54265426
}
54275427

src/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ class BufferValue : public MaybeStackBuffer<char> {
428428
if (name##_length > 0) \
429429
CHECK_NE(name##_data, nullptr);
430430

431+
// Use this when a variable or parameter is unused in order to explicitly
432+
// silence a compiler warning about that.
433+
template <typename T> inline void USE(T&&) {}
431434

432435
} // namespace node
433436

0 commit comments

Comments
 (0)