Skip to content

Commit 80615fc

Browse files
committed
[Java] Only generate lower bounds check on group wrap when min is greater than zero to avoid warning. Issue #616.
1 parent f8fd142 commit 80615fc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ private static void generateGroupClassHeader(
222222
indent + " }\n",
223223
dimensionHeaderLength));
224224

225+
final long minCount = numInGroupToken.encoding().applicableMinValue().longValue();
226+
final String minCheck = minCount > 0 ? "count < " + minCount + " || " : "";
227+
225228
sb.append(String.format("\n" +
226229
indent + " inline void wrapForEncode(char *buffer, const %3$s count," +
227230
" std::uint64_t *pos, const std::uint64_t actingVersion, const std::uint64_t bufferLength)\n" +
@@ -230,7 +233,7 @@ private static void generateGroupClassHeader(
230233
indent + "#pragma GCC diagnostic push\n" +
231234
indent + "#pragma GCC diagnostic ignored \"-Wtype-limits\"\n" +
232235
indent + "#endif\n" +
233-
indent + " if (count < %5$d || count > %6$d)\n" +
236+
indent + " if (%5$scount > %6$d)\n" +
234237
indent + " {\n" +
235238
indent + " throw std::runtime_error(\"count outside of allowed range [E110]\");\n" +
236239
indent + " }\n" +
@@ -250,7 +253,7 @@ private static void generateGroupClassHeader(
250253
indent + " *m_positionPtr = *m_positionPtr + %4$d;\n" +
251254
indent + " }\n",
252255
cppTypeForBlockLength, blockLength, cppTypeForNumInGroup, dimensionHeaderLength,
253-
numInGroupToken.encoding().applicableMinValue().longValue(),
256+
minCheck,
254257
numInGroupToken.encoding().applicableMaxValue().longValue()));
255258

256259
sb.append(String.format("\n" +
@@ -301,15 +304,17 @@ private static void generateGroupClassHeader(
301304
.append(indent).append(" {\n")
302305
.append(indent).append(" while (hasNext())\n")
303306
.append(indent).append(" {\n")
304-
.append(indent).append(" next(); func(*this);\n")
307+
.append(indent).append(" next();\n")
308+
.append(indent).append(" func(*this);\n")
305309
.append(indent).append(" }\n")
306310
.append(indent).append(" }\n\n")
307311
.append(indent).append("#else\n")
308312
.append(indent).append(" template<class Func> inline void forEach(Func&& func)\n")
309313
.append(indent).append(" {\n")
310314
.append(indent).append(" while (hasNext())\n")
311315
.append(indent).append(" {\n")
312-
.append(indent).append(" next(); func(*this);\n")
316+
.append(indent).append(" next();\n")
317+
.append(indent).append(" func(*this);\n")
313318
.append(indent).append(" }\n")
314319
.append(indent).append(" }\n\n")
315320
.append(indent).append("#endif\n\n");

0 commit comments

Comments
 (0)