Skip to content

Commit 3656611

Browse files
committed
Add SOCI_DUMMY_INIT() macro and use it
This allows to clearly indicate the initializations done just to avoid compiler warnings instead of having to write an ad hoc comment in every place where this was done. No real changes.
1 parent 854114f commit 3656611

File tree

13 files changed

+23
-16
lines changed

13 files changed

+23
-16
lines changed

include/soci/soci-platform.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ namespace cxx_details
144144

145145
#define SOCI_UNUSED(x) (void)x;
146146

147+
// This macro can be used to avoid warnings from MSVC (and sometimes from gcc,
148+
// if initialization is indirect) about "uninitialized" variables that are
149+
// actually always initialized. Using this macro makes it clear that the
150+
// initialization is only necessary to avoid compiler warnings and also will
151+
// allow us to define it as doing nothing if we ever use a compiler warning
152+
// about initializing variables unnecessarily.
153+
#define SOCI_DUMMY_INIT(x) (x)
154+
147155
#if defined(SOCI_HAVE_CXX11) || (defined(_MSC_VER) && _MSC_VER >= 1900)
148156
#define SOCI_NOEXCEPT noexcept
149157
#define SOCI_NOEXCEPT_FALSE noexcept(false)

src/backends/db2/vector-into-type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void db2_vector_into_type_backend::define_by_pos(
3434
this->data = data; // for future reference
3535
this->type = type; // for future reference
3636

37-
SQLINTEGER size = 0; // also dummy
37+
SQLINTEGER size SOCI_DUMMY_INIT(0);
3838

3939
switch (type)
4040
{
@@ -344,7 +344,7 @@ void db2_vector_into_type_backend::resize(std::size_t sz)
344344

345345
std::size_t db2_vector_into_type_backend::size()
346346
{
347-
std::size_t sz = 0; // dummy initialization to please the compiler
347+
std::size_t sz SOCI_DUMMY_INIT(0);
348348
switch (type)
349349
{
350350
// simple cases

src/backends/db2/vector-use-type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void db2_vector_use_type_backend::pre_use(indicator const *ind)
322322

323323
std::size_t db2_vector_use_type_backend::size()
324324
{
325-
std::size_t sz = 0; // dummy initialization to please the compiler
325+
std::size_t sz SOCI_DUMMY_INIT(0);
326326
switch (type)
327327
{
328328
// simple cases

src/backends/mysql/vector-into-type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void mysql_vector_into_type_backend::resize(std::size_t sz)
199199

200200
std::size_t mysql_vector_into_type_backend::size()
201201
{
202-
std::size_t sz = 0; // dummy initialization to please the compiler
202+
std::size_t sz SOCI_DUMMY_INIT(0);
203203
switch (type_)
204204
{
205205
// simple cases

src/backends/mysql/vector-use-type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void mysql_vector_use_type_backend::pre_use(indicator const *ind)
185185

186186
std::size_t mysql_vector_use_type_backend::size()
187187
{
188-
std::size_t sz = 0; // dummy initialization to please the compiler
188+
std::size_t sz SOCI_DUMMY_INIT(0);
189189
switch (type_)
190190
{
191191
// simple cases

src/backends/odbc/statement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ odbc_statement_backend::fetch(int number)
249249

250250
SQLSetStmtAttr(hstmt_, SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN, 0);
251251

252-
statement_backend::exec_fetch_result res = ef_success; // just for MSVC
252+
statement_backend::exec_fetch_result res SOCI_DUMMY_INIT(ef_success);
253253

254254
// Usually we try to fetch the entire vector at once, but if some into
255255
// string columns are bigger than 8KB (ODBC_MAX_COL_SIZE) then we use

src/backends/oracle/standard-into-type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ void oracle_standard_into_type_backend::define_by_pos(
6060
data_ = data; // for future reference
6161
type_ = type; // for future reference
6262

63-
ub2 oracleType = 0; // dummy initialization to please the compiler
64-
sb4 size = 0; // also dummy
63+
ub2 oracleType SOCI_DUMMY_INIT(0);
64+
sb4 size SOCI_DUMMY_INIT(0);
6565

6666
switch (type)
6767
{

src/backends/oracle/vector-into-type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void oracle_vector_into_type_backend::define_by_pos_bulk(
5252

5353
end_var_ = full_size();
5454

55-
ub2 oracleType = 0; // dummy initialization to please the compiler
56-
sb4 elementSize = 0; // also dummy
55+
ub2 oracleType SOCI_DUMMY_INIT(0);
56+
sb4 elementSize SOCI_DUMMY_INIT(0);
5757
void * dataBuf = NULL;
5858

5959
switch (type)

src/backends/postgresql/vector-into-type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ std::size_t postgresql_vector_into_type_backend::size()
260260

261261
std::size_t postgresql_vector_into_type_backend::full_size()
262262
{
263-
std::size_t sz = 0; // dummy initialization to please the compiler
263+
std::size_t sz SOCI_DUMMY_INIT(0);
264264
switch (type_)
265265
{
266266
// simple cases

src/backends/postgresql/vector-use-type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ std::size_t postgresql_vector_use_type_backend::size()
237237

238238
std::size_t postgresql_vector_use_type_backend::full_size()
239239
{
240-
std::size_t sz = 0; // dummy initialization to please the compiler
240+
std::size_t sz SOCI_DUMMY_INIT(0);
241241
switch (type_)
242242
{
243243
// simple cases

0 commit comments

Comments
 (0)