Skip to content

Commit 6f20f88

Browse files
committed
Fix -Wswitch warnings in isql
+ (inline) constexpr
1 parent 8bfaeef commit 6f20f88

File tree

2 files changed

+68
-64
lines changed

2 files changed

+68
-64
lines changed

src/isql/isql.epp

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -151,32 +151,32 @@ IsqlGlobals isqlGlob;
151151

152152
// Print lengths of numeric values
153153

154-
const int SHORT_LEN = 7; // NUMERIC (4,2) = -327.68
155-
const int LONG_LEN = 12; // NUMERIC (9,2) = -21474836.48
156-
const int INT64_LEN = 21; // NUMERIC(18,2) = -92233720368547758.08
157-
//const int QUAD_LEN = 19;
158-
const int FLOAT_LEN = 14; // -1.2345678E+38
159-
const int DOUBLE_LEN = 23; // -1.234567890123456E+300
160-
const int DATE_LEN = 11; // 11 for date only
161-
const int DATETIME_LEN = 25; // 25 for date-time
162-
const int DATETIME_TZ_LEN = DATETIME_LEN - 1 + 1 + TimeZoneUtil::MAX_LEN; // DATETIME_LEN should be 24
163-
const int TIME_ONLY_LEN = 13; // 13 for time only
164-
const int TIME_TZ_ONLY_LEN = TIME_ONLY_LEN + 1 + TimeZoneUtil::MAX_LEN;
165-
const int DATE_ONLY_LEN = 11;
166-
const int BOOLEAN_LEN = 7; // <false>
167-
const int UNKNOWN_LEN = 20; // Unknown type: %d
168-
169-
const int MAX_TERMS = 10; // max # of terms in an interactive cmd
170-
171-
const char* ISQL_COUNTERS_SET = "CurrentMemory, MaxMemory, RealTime, UserTime, Buffers, Reads, Writes, Fetches";
172-
const int ISQL_COUNTERS = 8;
173-
174-
const char* UNKNOWN = "*unknown*";
154+
constexpr int SHORT_LEN = 7; // NUMERIC (4,2) = -327.68
155+
constexpr int LONG_LEN = 12; // NUMERIC (9,2) = -21474836.48
156+
constexpr int INT64_LEN = 21; // NUMERIC(18,2) = -92233720368547758.08
157+
//constexpr int QUAD_LEN = 19;
158+
constexpr int FLOAT_LEN = 14; // -1.2345678E+38
159+
constexpr int DOUBLE_LEN = 23; // -1.234567890123456E+300
160+
constexpr int DATE_LEN = 11; // 11 for date only
161+
constexpr int DATETIME_LEN = 25; // 25 for date-time
162+
constexpr int DATETIME_TZ_LEN = DATETIME_LEN - 1 + 1 + TimeZoneUtil::MAX_LEN; // DATETIME_LEN should be 24
163+
constexpr int TIME_ONLY_LEN = 13; // 13 for time only
164+
constexpr int TIME_TZ_ONLY_LEN = TIME_ONLY_LEN + 1 + TimeZoneUtil::MAX_LEN;
165+
constexpr int DATE_ONLY_LEN = 11;
166+
constexpr int BOOLEAN_LEN = 7; // <false>
167+
constexpr int UNKNOWN_LEN = 20; // Unknown type: %d
168+
169+
constexpr int MAX_TERMS = 10; // max # of terms in an interactive cmd
170+
171+
constexpr const char* ISQL_COUNTERS_SET = "CurrentMemory, MaxMemory, RealTime, UserTime, Buffers, Reads, Writes, Fetches";
172+
constexpr int ISQL_COUNTERS = 8;
173+
174+
constexpr const char* UNKNOWN = "*unknown*";
175175

176176
namespace IcuUtil
177177
{
178178
// Duplicate from ICU to not need to link ISQL with it. It's used by U8_NEXT_UNSAFE.
179-
static const uint8_t utf8_countTrailBytes[256] = {
179+
static constexpr uint8_t utf8_countTrailBytes[256] = {
180180
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
181181
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
182182
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1638,6 +1638,9 @@ bool ISQL_statement_ends_in_comment(const char* statement)
16381638
if (!altQuoteChar || lastChar == altQuoteChar)
16391639
state = normal;
16401640
break;
1641+
1642+
default:
1643+
break;
16411644
}
16421645
break;
16431646

@@ -1650,6 +1653,8 @@ bool ISQL_statement_ends_in_comment(const char* statement)
16501653
case in_double_quoted_string:
16511654
state = normal;
16521655
break;
1656+
default:
1657+
break;
16531658
}
16541659
break;
16551660

@@ -6005,7 +6010,7 @@ static bool isyesno(const TEXT* buffer)
60056010

60066011
static bool printUser(const char* dbName)
60076012
{
6008-
unsigned char info[] = {fb_info_username, fb_info_sqlrole};
6013+
constexpr unsigned char info[] = {fb_info_username, fb_info_sqlrole};
60096014
unsigned char buffer[(1 + 2 + MAX_SQL_IDENTIFIER_SIZE) * 2 + 2];
60106015
string login, role;
60116016

@@ -6111,7 +6116,7 @@ static bool printUser(const char* dbName)
61116116
const char* text;
61126117
const char* skip;
61136118
};
6114-
FieldInfo fieldInfo[2] = {
6119+
constexpr FieldInfo fieldInfo[2] = {
61156120
{"User", NULL},
61166121
{"Role", "NONE"}
61176122
};
@@ -6681,7 +6686,7 @@ static processing_state parse_arg(int argc, SCHAR** argv, QualifiedMetaString& t
66816686

66826687
// Interpret each command line argument
66836688

6684-
const SCHAR switchchar = '-';
6689+
constexpr SCHAR switchchar = '-';
66856690

66866691
#ifdef DEV_BUILD
66876692
bool istable = false;
@@ -7781,7 +7786,7 @@ static processing_state print_line(Firebird::IMessageMetadata* message, UCHAR* b
77817786
* line = pointer to the line buffer.
77827787
*
77837788
**************************************/
7784-
const unsigned maxblob = 20;
7789+
constexpr unsigned maxblob = 20;
77857790
IsqlVar varlist[maxblob]; // No more than 20 blobs per line
77867791
unsigned varnum = 0;
77877792

@@ -9179,7 +9184,7 @@ void PerTableStats::printStats(Firebird::IAttachment* att)
91799184
string h;
91809185

91819186
const unsigned lenTable = maxTabLen < 32 ? 32 : FB_ALIGN(maxTabLen, 4);
9182-
const unsigned lenValue = 9;
9187+
constexpr unsigned lenValue = 9;
91839188

91849189
h.append(lenTable, '-');
91859190
h.append(1, '+');

src/isql/isql.h

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,21 @@
4141

4242
// Define lengths used in isql.e
4343

44-
const int PRINT_BUFFER_LENGTH = 1024;
45-
const int MAXTERM_SIZE = 32; // SQL termination character
46-
const int USER_LENGTH = 128;
47-
const int PASSWORD_LENGTH = 128;
48-
const int ROLE_LENGTH = 128;
44+
inline constexpr int PRINT_BUFFER_LENGTH = 1024;
45+
inline constexpr int MAXTERM_SIZE = 32; // SQL termination character
46+
inline constexpr int USER_LENGTH = 128;
47+
inline constexpr int PASSWORD_LENGTH = 128;
48+
inline constexpr int ROLE_LENGTH = 128;
4949

5050
/* these constants are purely idiotic; there's no point in having
51-
a predefined constant with no meaning, but that's Ed Simon the
52-
master programmer for you! */
51+
a predefined constant with no meaning... */
5352

54-
const int BUFFER_LENGTH128 = 128;
55-
const int BUFFER_LENGTH256 = 256;
56-
const int BUFFER_LENGTH400 = 400;
57-
const int BUFFER_LENGTH512 = 512;
58-
const int BUFFER_LENGTH60 = 60;
59-
const int BUFFER_LENGTH180 = 180;
53+
inline constexpr int BUFFER_LENGTH128 = 128;
54+
inline constexpr int BUFFER_LENGTH256 = 256;
55+
inline constexpr int BUFFER_LENGTH400 = 400;
56+
inline constexpr int BUFFER_LENGTH512 = 512;
57+
inline constexpr int BUFFER_LENGTH60 = 60;
58+
inline constexpr int BUFFER_LENGTH180 = 180;
6059

6160
// Define the possible states of processing commands
6261

@@ -78,8 +77,8 @@ enum processing_state {
7877

7978
// Which blob subtypes to print
8079

81-
const int ALL_BLOBS = -2;
82-
const int NO_BLOBS = -1;
80+
inline constexpr int ALL_BLOBS = -2;
81+
inline constexpr int NO_BLOBS = -1;
8382

8483
// Flag to decode all vs sql only objects
8584
enum LegacyTables
@@ -88,24 +87,24 @@ enum LegacyTables
8887
ALL_objects
8988
};
9089

91-
const size_t QUOTED_NAME_SIZE = MAX_SQL_IDENTIFIER_SIZE + 2 /* quotes */;
90+
inline constexpr size_t QUOTED_NAME_SIZE = MAX_SQL_IDENTIFIER_SIZE + 2 /* quotes */;
9291

93-
const size_t CHARSET_COLLATE_SIZE =
92+
inline constexpr size_t CHARSET_COLLATE_SIZE =
9493
(MAX_SQL_IDENTIFIER_LEN + 2 /* quotes */) * 2 + // charset and collate names
9594
14 + // CHARACTER SET
9695
9 + // NOT NULL
9796
8 + // COLLATE
9897
30 + // extra space
9998
1; // null terminator
10099

101-
static const char* const DEFTERM = ";";
102-
const unsigned NULL_DISP_LEN = 6;
100+
static inline constexpr const char* DEFTERM = ";";
101+
inline constexpr unsigned NULL_DISP_LEN = 6;
103102

104103

105104
// Error codes
106105

107-
const int MSG_LENGTH = 1024;
108-
const int ISQL_MSG_FAC = FB_IMPL_MSG_FACILITY_ISQL;
106+
inline constexpr int MSG_LENGTH = 1024;
107+
inline constexpr int ISQL_MSG_FAC = FB_IMPL_MSG_FACILITY_ISQL;
109108

110109
#define FB_IMPL_MSG_NO_SYMBOL(facility, number, text)
111110

@@ -130,7 +129,7 @@ struct sqltypes
130129
SCHAR type_name[QUOTED_NAME_SIZE];
131130
};
132131

133-
static const sqltypes Column_types[] = {
132+
static inline constexpr sqltypes Column_types[] = {
134133
{blr_short, "SMALLINT"},
135134
{blr_long, "INTEGER"},
136135
{blr_quad, "QUAD"},
@@ -160,35 +159,35 @@ static const sqltypes Column_types[] = {
160159

161160
const int MAX_INTSUBTYPES = 2;
162161

163-
static const SCHAR* Integral_subtypes[] = {
162+
static inline constexpr const SCHAR* Integral_subtypes[] = {
164163
"UNKNOWN", // Defined type, keyword
165164
"NUMERIC", // NUMERIC, keyword
166165
"DECIMAL" // DECIMAL, keyword
167166
};
168167

169168
// Text subtypes
170169

171-
const int MAX_TEXTSUBTYPES = 1;
170+
inline constexpr int MAX_TEXTSUBTYPES = 1;
172171

173-
static const SCHAR* Text_subtypes[] = {
172+
static inline constexpr const SCHAR* Text_subtypes[] = {
174173
"CHAR",
175174
"BINARY"
176175
};
177176

178177
// Varying subtypes
179178

180-
const int MAX_VARYINGSUBTYPES = 1;
179+
inline constexpr int MAX_VARYINGSUBTYPES = 1;
181180

182-
static const SCHAR* Varying_subtypes[] = {
181+
static inline constexpr const SCHAR* Varying_subtypes[] = {
183182
"VARCHAR",
184183
"VARBINARY"
185184
};
186185

187186
// Blob subtypes
188187

189-
const int MAX_BLOBSUBTYPES = 8;
188+
inline constexpr int MAX_BLOBSUBTYPES = 8;
190189

191-
static const SCHAR* Sub_types[] = {
190+
static inline constexpr const SCHAR* Sub_types[] = {
192191
"BINARY", // keyword
193192
"TEXT", // keyword
194193
"BLR", // keyword
@@ -210,9 +209,9 @@ BY REFERENCE_WITH_NULL his supported in FB2 to be able to signal SQL NULL
210209
in input parameters.
211210
The names mentioned here are documented in jrd/types.h. */
212211

213-
const int MAX_UDFPARAM_TYPES = 6;
212+
inline constexpr int MAX_UDFPARAM_TYPES = 6;
214213

215-
static const char* UDF_param_types[] = {
214+
static inline constexpr const char* UDF_param_types[] = {
216215
" BY VALUE", // keyword
217216
"", // BY REFERENCE
218217
" BY DESCRIPTOR", // keyword in FB, internally VMS descriptor
@@ -251,7 +250,7 @@ class IsqlGlobals
251250

252251
extern IsqlGlobals isqlGlob;
253252

254-
static const char* const SCRATCH = "fb_query_";
253+
static inline constexpr const char* SCRATCH = "fb_query_";
255254

256255
inline void STDERROUT(const char* st, bool cr = true)
257256
{
@@ -268,12 +267,12 @@ inline void STDERROUT(const char* st, bool cr = true)
268267
#endif
269268
#define ISQL_FREE(x) {gds__free(x); x = NULL;}
270269

271-
static const char* const NEWLINE = "\n";
272-
static const char* const TAB_AS_SPACES = " ";
270+
static inline constexpr const char* NEWLINE = "\n";
271+
static inline constexpr const char* TAB_AS_SPACES = " ";
273272

274-
const char BLANK = '\040';
275-
const char DBL_QUOTE = '\042';
276-
const char SINGLE_QUOTE = '\'';
273+
inline constexpr char BLANK = '\040';
274+
inline constexpr char DBL_QUOTE = '\042';
275+
inline constexpr char SINGLE_QUOTE = '\'';
277276

278277
struct IsqlVar
279278
{

0 commit comments

Comments
 (0)