Skip to content

Commit 938e68f

Browse files
committed
WL15065 Fix code to build cleanly with clang
Enable warnings on all connector Change-Id: I9ca932cac013d7602e6867e3063cd94583a403ca
1 parent 534eac1 commit 938e68f

33 files changed

+362
-310
lines changed

cdk/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ IF(MSVC)
187187
# Note: 4520 only present on Visual Studio 12
188188

189189
if (MSVC_VERSION LESS 1800)
190-
add_compile_options(
190+
add_flags(
191191
/wd4127 # conditional expression is constant (needed for do {...} while(false))
192192
/wd4512 # assignment operator could not be generated
193193
/wd4100 # unreferenced formal parameter
@@ -208,9 +208,10 @@ ELSE()
208208

209209
if(SUNPRO)
210210
# TODO: Enable -Wall after fixing warnings
211-
add_compile_options(-errtags=yes -erroff=hidevf)
211+
add_flags(-errtags=yes -erroff=hidevf)
212212
else()
213213
add_compile_options(-Wall)
214+
add_flags(CXX -Wall)
214215
endif()
215216

216217
ENDIF()

cdk/cmake/bootstrap.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ function(bootstrap)
8181
list(APPEND cmake_opts "-D" "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
8282
endif()
8383

84+
if(CMAKE_C_COMPILER)
85+
message("-- C compiler: ${CMAKE_C_COMPILER}")
86+
list(APPEND cmake_opts "-D" "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
87+
endif()
88+
89+
if(CMAKE_CXX_COMPILER)
90+
message("-- C++ compiler: ${CMAKE_CXX_COMPILER}")
91+
list(APPEND cmake_opts "-D" "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
92+
endif()
93+
8494
message("-- ----")
8595

8696
execute_process(

cdk/cmake/testing.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ IF(WITH_TESTS)
182182

183183
elseif((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
184184

185+
#TODO: Remove -Wno-delete-non-abstract-non-virtual-dtor when bumping ABI and
186+
# adding virtual destructor for DbDoc, Value and Column_detail
185187
target_compile_options(${TEST} PRIVATE
186-
-Wno-unused-value
188+
-Wno-unused-value -Wno-delete-non-abstract-non-virtual-dtor
187189
)
188190

189191
else()
@@ -318,10 +320,9 @@ IF(WITH_TESTS)
318320
)
319321

320322
elseif((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
321-
322-
target_compile_options(${target_run_unit_tests} PRIVATE
323-
-Wno-unused-value
324-
)
323+
target_compile_options(${target_run_unit_tests} PRIVATE
324+
-Wno-unused-value -Wno-delete-non-abstract-non-virtual-dtor
325+
)
325326

326327
else()
327328
#target_compile_options(${target_run_unit_tests} PRIVATE -Wno-unused-result)

cdk/parser/tests/parser-t.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ TEST(Parser, doc_path)
14191419
Doc_field_parser doc_path(test);
14201420
doc_path.process(path);
14211421

1422-
EXPECT_EQ(3, path.length());
1422+
EXPECT_EQ(3U, path.length());
14231423
EXPECT_EQ(path.DOUBLE_ASTERISK, path.get_el(0).m_type);
14241424
EXPECT_EQ(path.MEMBER, path.get_el(1).m_type);
14251425
EXPECT_EQ(cdk::string("date"), path.get_el(1).m_name);
@@ -1435,7 +1435,7 @@ TEST(Parser, doc_path)
14351435
Doc_field_parser doc_path(test);
14361436
doc_path.process(path);
14371437

1438-
EXPECT_EQ(3, path.length());
1438+
EXPECT_EQ(3U, path.length());
14391439
EXPECT_EQ(path.DOUBLE_ASTERISK, path.get_el(0).m_type);
14401440
EXPECT_EQ(path.MEMBER, path.get_el(1).m_type);
14411441
EXPECT_EQ(cdk::string("date"), path.get_el(1).m_name);
@@ -1451,7 +1451,7 @@ TEST(Parser, doc_path)
14511451
Doc_field_parser doc_path(test);
14521452
doc_path.process(path);
14531453

1454-
EXPECT_EQ(3, path.length());
1454+
EXPECT_EQ(3U, path.length());
14551455
EXPECT_EQ(path.MEMBER, path.get_el(0).m_type);
14561456
EXPECT_EQ(cdk::string("date"), path.get_el(0).m_name);
14571457
EXPECT_EQ(path.MEMBER, path.get_el(1).m_type);

cmake/libutils/save_linker_opts.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int main(int argc, char* argv[])
5353

5454
// Note: argv[2] is the compiler/linker command
5555

56-
for(unsigned pos=3; pos < argc; pos++)
56+
for(int pos=3; pos < argc; pos++)
5757
{
5858
if(string(argv[pos]) == "-o")
5959
{

common/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ add_library(common STATIC
3535

3636
target_link_libraries(common cdk)
3737

38+
#TODO: Remove -Wno-delete-non-abstract-non-virtual-dtor when bumping ABI and
39+
# adding virtual destructor for DbDoc, Value and Column_detail
40+
if(CLANG)
41+
target_compile_options(common PRIVATE
42+
-Wno-delete-non-abstract-non-virtual-dtor
43+
)
44+
endif()
45+
3846
#
3947
# Generate version info
4048
#

common/op_impl.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ class Op_sort
844844
return m_order.empty() ? nullptr : this;
845845
}
846846

847-
private:
847+
protected:
848848

849849
// cdk::Order_by interface
850850

@@ -881,8 +881,10 @@ class Op_sort
881881

882882
prc.list_end();
883883
}
884-
};
885884

885+
using Base::process;
886+
887+
};
886888

887889
/*
888890
This template adds to the given Base class implementations of Having_if
@@ -931,7 +933,7 @@ class Op_having
931933
return m_having.empty() ? nullptr : this;
932934
}
933935

934-
private:
936+
protected:
935937

936938
// cdk::Expression processor
937939

@@ -940,6 +942,8 @@ class Op_having
940942
parser::Expression_parser expr_parser(PM, m_having);
941943
expr_parser.process(prc);
942944
}
945+
946+
using Base::process;
943947
};
944948

945949

@@ -987,7 +991,7 @@ class Op_group_by
987991
return m_group_by.empty() ? nullptr : this;
988992
}
989993

990-
private:
994+
protected:
991995

992996
// Expr_list
993997

@@ -1003,8 +1007,9 @@ class Op_group_by
10031007

10041008
prc.list_end();
10051009
}
1006-
};
10071010

1011+
using Base::process;
1012+
};
10081013

10091014
/*
10101015
This template adds to the given Base class implementations of Proj_if
@@ -1133,6 +1138,8 @@ class Op_projection
11331138

11341139
}
11351140

1141+
using Base::process;
1142+
11361143
// cdk::Projection
11371144

11381145
void process(cdk::Projection::Processor& prc) const override
@@ -2413,6 +2420,12 @@ class Op_collection_modify
24132420
{
24142421
using string = std::string;
24152422
using Impl = common::Collection_modify_if;
2423+
using Base = Op_select<doc_mode,
2424+
Op_sort<doc_mode,
2425+
Op_limit<
2426+
Op_bind<
2427+
Op_base<
2428+
common::Collection_modify_if>>>>>;
24162429

24172430
Object_ref m_coll;
24182431

@@ -2574,6 +2587,7 @@ class Op_collection_modify
25742587
}
25752588
}
25762589

2590+
using Base::process;
25772591
};
25782592

25792593

@@ -2998,6 +3012,7 @@ class Op_table_update
29983012
);
29993013
}
30003014

3015+
using Base::process;
30013016

30023017
// cdk::api::Column_ref
30033018

common/session.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,6 @@ void Settings_impl::get_data_source(cdk::ds::Multi_source &src)
505505
If DNS+SRV is not used, get list of hosts from the settings.
506506
*/
507507

508-
// if priorities were not set explicitly, assign decreasing starting from 100
509-
int prio = m_data.m_user_priorities ? -1 : 100;
510-
511508
/*
512509
Look for a priority after host/socket setting. If explicit priorities
513510
are used, then we expect the priority setting to be present and we throw
@@ -603,7 +600,7 @@ void Settings_impl::get_data_source(cdk::ds::Multi_source &src)
603600
throw_error("Unix socket connections not supported on Windows platform.");
604601
};
605602
#else
606-
auto add_socket = [this, &src, &opts, check_prio](iterator &it, int prio) {
603+
auto add_socket = [&src, &opts, check_prio](iterator &it, int prio) {
607604

608605
assert(Session_option_impl::SOCKET == it->first);
609606

@@ -956,8 +953,6 @@ Session_pool::get_session(Session_cleanup *cleanup)
956953
{
957954
lock_guard guard(m_pool_mutex);
958955

959-
bool use_blocklist = true;
960-
961956
if (!m_pool_enable)
962957
{
963958
return std::shared_ptr<cdk::Session>(new cdk::Session(m_ds));

devapi/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,13 @@ target_link_libraries(devapi PUBLIC common)
4444

4545
add_coverage(devapi)
4646

47+
#TODO: Remove -Wno-delete-non-abstract-non-virtual-dtor when bumping ABI and
48+
# adding virtual destructor for DbDoc, Value and Column_detail
49+
if((CMAKE_C_COMPILER_ID MATCHES "Clang") OR(CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
50+
target_compile_options(devapi PRIVATE
51+
-Wno-delete-non-abstract-non-virtual-dtor
52+
)
53+
endif()
54+
4755

4856
add_subdirectory(tests)

devapi/document.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ Value Value::Access::mk_from_json(const std::string &json)
428428

429429
parser.process(builder);
430430

431-
return std::move(val);
431+
return val;
432432
}
433433

434434

@@ -461,7 +461,7 @@ DbDoc::Iterator DbDoc::begin()
461461
m_impl->reset();
462462
it.m_impl = m_impl;
463463
it.m_end = false;
464-
return std::move(it);
464+
return it;
465465
}
466466
CATCH_AND_WRAP
467467
}
@@ -475,7 +475,7 @@ DbDoc::Iterator DbDoc::end()
475475
*/
476476
Iterator it;
477477
it.m_end = true;
478-
return std::move(it);
478+
return it;
479479
}
480480
CATCH_AND_WRAP
481481
}

devapi/result.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ struct CollationInfo::Access
316316
ci.m_id = _id;
317317
ci.m_case = CollationInfo::coll_case(_case);
318318
ci.m_name = _name;
319-
return std::move(ci);
319+
return ci;
320320
}
321321
};
322322

devapi/session.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ POP_SYS_WARNINGS
4646

4747

4848

49-
const unsigned max_priority = 100;
50-
5149
using namespace ::mysqlx::impl::common;
5250
using namespace ::mysqlx::internal;
5351
using namespace ::mysqlx;

devapi/tests/batch-t.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ TEST_F(Batch, crud)
8383
{
8484
RowResult res = sql("select count(*) from test.c1");
8585
unsigned cnt = res.fetchOne()[0];
86-
EXPECT_EQ(0, cnt);
86+
EXPECT_EQ(0U, cnt);
8787
}
8888

8989
cout << "Inserting documents..." << endl;
@@ -112,7 +112,7 @@ TEST_F(Batch, crud)
112112
{
113113
RowResult res = sql("select count(*) from test.c1");
114114
unsigned cnt = res.fetchOne()[0];
115-
EXPECT_EQ(5, cnt);
115+
EXPECT_EQ(5U, cnt);
116116
cout << "Documents added" << endl;
117117
}
118118

@@ -149,7 +149,7 @@ TEST_F(Batch, crud)
149149
EXPECT_FALSE(find.fetchOne());
150150
RowResult res = sql("select count(*) from test.c1");
151151
unsigned cnt = res.fetchOne()[0];
152-
EXPECT_EQ(5, cnt);
152+
EXPECT_EQ(5U, cnt);
153153
}
154154

155155
cout << "Modifying documents..." << endl;
@@ -178,7 +178,7 @@ TEST_F(Batch, crud)
178178
EXPECT_NO_THROW(doc["food"]);
179179
EXPECT_THROW(doc["date"], std::out_of_range);
180180
}
181-
EXPECT_EQ(5, pos);
181+
EXPECT_EQ(5U, pos);
182182
}
183183

184184
cout << "Done!" << endl;
@@ -203,13 +203,13 @@ TEST_F(Batch, multi_add)
203203

204204
coll.remove("true").execute();
205205
coll.add(docs).execute();
206-
EXPECT_EQ(5, show_docs(coll));
206+
EXPECT_EQ(5U, show_docs(coll));
207207

208208
cout << endl << "2. Add range of documents from 1 to 3" << endl;
209209

210210
coll.remove("true").execute();
211211
coll.add(docs.begin(), docs.begin() + 3).execute();
212-
EXPECT_EQ(3, show_docs(coll));
212+
EXPECT_EQ(3U, show_docs(coll));
213213

214214
cout << endl << "3. Mixed inserts" << endl;
215215

@@ -219,7 +219,7 @@ TEST_F(Batch, multi_add)
219219
.add(docs.begin(), docs.begin() + 3)
220220
.add(docs[4])
221221
.add(docs).execute();
222-
EXPECT_EQ(15, show_docs(coll));
222+
EXPECT_EQ(15U, show_docs(coll));
223223

224224
cout << endl << "4. Add documents in a loop" << endl;
225225

@@ -231,7 +231,7 @@ TEST_F(Batch, multi_add)
231231
add_op.add(json);
232232
}
233233
add_op.execute();
234-
EXPECT_EQ(5, show_docs(coll));
234+
EXPECT_EQ(5U, show_docs(coll));
235235
}
236236

237237
cout << endl << "5. Using custom iterator" << endl;
@@ -269,7 +269,7 @@ TEST_F(Batch, multi_add)
269269

270270
coll.remove("true").execute();
271271
coll.add(It(5), It()).execute();
272-
EXPECT_EQ(5, show_docs(coll));
272+
EXPECT_EQ(5U, show_docs(coll));
273273

274274
}
275275

@@ -310,7 +310,7 @@ TEST_F(Batch, table_insert)
310310
cout << "row#" << count << ": " << row[0] << ", " << row[1] << endl;
311311
}
312312

313-
EXPECT_EQ(8, count);
313+
EXPECT_EQ(8U, count);
314314
}
315315

316316
tbl.insert().rows(rows.begin(), rows.end()).values(6, "new").execute();
@@ -328,7 +328,7 @@ TEST_F(Batch, table_insert)
328328
cout << "row#" << count << ": " << row[0] << ", " << row[1] << endl;
329329
}
330330

331-
EXPECT_EQ(14, count);
331+
EXPECT_EQ(14U, count);
332332
}
333333
}
334334

0 commit comments

Comments
 (0)