Skip to content

Commit 979de54

Browse files
committed
build: support -Wshadow
Since libev and sha1 do not suite very strict GCC shadowing rules, the commit does not enable shadowing warning for these third-party libraries.
1 parent 067ce92 commit 979de54

File tree

13 files changed

+52
-42
lines changed

13 files changed

+52
-42
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ FIND_PACKAGE (benchmark QUIET)
1111

1212
SET(CMAKE_CXX_STANDARD 17)
1313
SET(CMAKE_C_STANDARD 11)
14-
ADD_COMPILE_OPTIONS(-Wall -Wextra -Werror)
14+
ADD_COMPILE_OPTIONS(-Wall -Wextra -Werror -Wshadow)
1515

1616
ADD_LIBRARY(tntcxx INTERFACE)
1717
ADD_LIBRARY(tntcxx::tntcxx ALIAS tntcxx)

examples/Simple.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ main()
155155
uint32_t limit = 1;
156156
uint32_t offset = 0;
157157
IteratorType iter = IteratorType::EQ;
158-
auto i = conn.space[space_id].index[index_id];
159-
rid_t select = i.select(std::make_tuple(pk_value), limit, offset, iter);
158+
auto index = conn.space[space_id].index[index_id];
159+
rid_t select = index.select(std::make_tuple(pk_value), limit, offset, iter);
160160
//doclabel09-2
161161
/*
162162
* Now let's send our requests to the server. There are two options

examples/Sql.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ main()
226226
client.waitAll(conn, prepared_select_futures);
227227
for (size_t i = 0; i < prepared_select_futures.size(); ++i) {
228228
assert(conn.futureIsReady(prepared_select_futures[i]));
229-
Response<Buf_t> response =
230-
conn.getResponse(prepared_select_futures[i]);
229+
response = conn.getResponse(prepared_select_futures[i]);
231230
printResponse<Buf_t>(response);
232231
}
233232

src/Client/Connection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ static constexpr ssize_t CONN_READAHEAD = 64 * 1024;
4646
static constexpr size_t IOVEC_MAX_SIZE = 32;
4747

4848
struct ConnectionError {
49-
ConnectionError(const std::string &msg, int errno_ = 0) :
50-
msg(msg), saved_errno(errno_)
49+
ConnectionError(const std::string &errmsg, int errno_ = 0) :
50+
msg(errmsg), saved_errno(errno_)
5151
{
5252
}
5353

src/Client/LibevNetProvider.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@
4242
#include <string_view>
4343

4444
#include "Connection.hpp"
45+
46+
/**
47+
* Disable -Wshadow for libev because ev_loop function shadows
48+
* declaration of struct ev_loop constructor.
49+
*/
50+
#pragma GCC diagnostic push
51+
#pragma GCC diagnostic ignored "-Wshadow"
4552
#include "ev.h"
53+
#pragma GCC diagnostic pop
4654

4755
template<class BUFFER, class Stream>
4856
class Connector;

src/Client/UnixPlainStream.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ class UnixPlainStream : public UnixStream {
7272
/////////////////////////////////////////////////////////////////////
7373

7474
int
75-
UnixPlainStream::connect(const ConnectOptions &opts)
75+
UnixPlainStream::connect(const ConnectOptions &opts_arg)
7676
{
77-
if (opts.transport != STREAM_PLAIN)
77+
if (opts_arg.transport != STREAM_PLAIN)
7878
US_DIE("Non-plain socket are unsupported in this build."
7979
"Consider enabling it with -DTNTCXX_ENABLE_TLS.");
80-
return UnixStream::connect(opts);
80+
return UnixStream::connect(opts_arg);
8181
}
8282

8383
namespace internal {

src/Utils/Sha1.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
#include <array>
3434
#include <utility>
3535

36+
#pragma GCC diagnostic push
37+
#pragma GCC diagnostic ignored "-Wshadow"
3638
#include "../third_party/sha1.hpp"
39+
#pragma GCC diagnostic pop
3740

3841
namespace tnt {
3942

src/mpp/Dec.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,13 @@ struct Jumps {
547547
/** Override given tag with special jump. */
548548
template <size_t... I>
549549
static constexpr data_t
550-
build_inject(data_t orig, uint8_t tag, jump_t inject, tnt::iseq<I...>)
550+
build_inject(data_t orig, uint8_t tag, jump_t jump, tnt::iseq<I...>)
551551
{
552-
return {(I != tag ? orig[I] : inject)...};
552+
return {(I != tag ? orig[I] : jump)...};
553553
}
554554

555-
constexpr Jumps(Jumps a, uint8_t tag, jump_t inject)
556-
: data(build_inject(a.data, tag, inject, is256))
555+
constexpr Jumps(Jumps a, uint8_t tag, jump_t jump)
556+
: data(build_inject(a.data, tag, jump, is256))
557557
{
558558
}
559559

test/BufferPerfTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ struct StaticBuffer {
5656

5757
template <size_t... I, class... T>
5858
void
59-
gen_helper(std::index_sequence<I...>, std::tuple<T...>& t)
59+
gen_helper(std::index_sequence<I...>, std::tuple<T...>& ts)
6060
{
6161
auto set = [](auto& t) { t = rand(); };
62-
(set(std::get<I>(t)), ...);
62+
(set(std::get<I>(ts)), ...);
6363
}
6464

6565
template <class... T>

test/BufferUnitTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ buffer_release()
541541
* should remain unchanged.
542542
*/
543543
int i = 0;
544-
for (auto tmp = buf.begin(); tmp < mid_itr; ++tmp) {
545-
tmp.get(res);
544+
for (auto tmp_it = buf.begin(); tmp_it < mid_itr; ++tmp_it) {
545+
tmp_it.get(res);
546546
fail_unless(res == char_samples[i++ % SAMPLES_CNT]);
547547
}
548548
}

0 commit comments

Comments
 (0)