Fix narrowing warning [duplicate]

1 week ago 9
ARTICLE AD BOX

Building my program on gcc (some old version), I got:

narrowing conversion of '(schemaName.std::__cxx11::basic_string<wchar_t>::length()+ 2)' from 'std::__cxx11::basic_string<wchar_t>::size_type' {aka 'long unsigned int'} to 'int'[-Wnarrowing]

How to fix it? Or I should just silence it?

This is the line in question:

int length1[2] = { schemaName.length() + 2, tableName.length() + 2 };

length1 array will be passed to PQprepare: https://www.postgresql.org/docs/current/libpq-exec.html, which is looking for an int[].

P..S.: Is there a way to turn this on on MSVC 2017?

Igor's user avatar

14

Read Entire Article