Skip to content

Commit da6305b

Browse files
committed
Fix compiler warnings caused by ASSERT_HOST
The modified definition avoids warnings caused by redundant semicolons. Now a semicolon is required when using the macro, so a few code locations had to be updated. Signed-off-by: Stefan Weil <[email protected]>
1 parent 44a6d9f commit da6305b

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

src/ccmain/osdetect.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ int orientation_and_script_detection(STRING& filename,
198198
if (lastdot != nullptr)
199199
name[lastdot-name.string()] = '\0';
200200

201-
ASSERT_HOST(tess->pix_binary() != nullptr)
201+
ASSERT_HOST(tess->pix_binary() != nullptr);
202202
int width = pixGetWidth(tess->pix_binary());
203203
int height = pixGetHeight(tess->pix_binary());
204204

src/ccmain/pgedit.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: pgedit.cpp (Formerly pgeditor.c)
33
* Description: Page structure file editor
44
* Author: Phil Cheatle
5-
* Created: Thu Oct 10 16:25:24 BST 1991
65
*
76
*(C) Copyright 1991, Hewlett-Packard Ltd.
87
** Licensed under the Apache License, Version 2.0(the "License");
@@ -22,10 +21,10 @@
2221
#include "config_auto.h"
2322
#endif
2423

25-
#include "pgedit.h"
24+
#include "pgedit.h"
2625

27-
#include <cctype>
28-
#include <cmath>
26+
#include <cctype>
27+
#include <cmath>
2928

3029
#include "blread.h"
3130
#include "control.h"
@@ -879,7 +878,7 @@ bool Tesseract::word_display(PAGE_RES_IT* pr_it) {
879878
text += best_choice_str;
880879
IncorrectResultReason reason = (blamer_bundle == nullptr) ?
881880
IRR_PAGE_LAYOUT : blamer_bundle->incorrect_result_reason();
882-
ASSERT_HOST(reason < IRR_NUM_REASONS)
881+
ASSERT_HOST(reason < IRR_NUM_REASONS);
883882
blame += " [";
884883
blame += BlamerBundle::IncorrectReasonName(reason);
885884
blame += "]";

src/ccstruct/blobbox.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: blobbox.cpp (Formerly blobnbox.c)
33
* Description: Code for the textord blob class.
44
* Author: Ray Smith
5-
* Created: Thu Jul 30 09:08:51 BST 1992
65
*
76
* (C) Copyright 1992, Hewlett-Packard Ltd.
87
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -71,7 +70,7 @@ void BLOBNBOX::reflect_box_in_y_axis() {
7170
// correction can be applied.
7271
void BLOBNBOX::rotate_box(FCOORD rotation) {
7372
if (IsDiacritic()) {
74-
ASSERT_HOST(rotation.x() >= kCosSmallAngle)
73+
ASSERT_HOST(rotation.x() >= kCosSmallAngle);
7574
ICOORD top_pt((box.left() + box.right()) / 2, base_char_top_);
7675
ICOORD bottom_pt(top_pt.x(), base_char_bottom_);
7776
top_pt.rotate(rotation);

src/ccutil/errcode.h

+13-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: errcode.h (Formerly error.h)
33
* Description: Header file for generic error handler class
44
* Author: Ray Smith
5-
* Created: Tue May 1 16:23:36 BST 1990
65
*
76
* (C) Copyright 1990, Hewlett-Packard Ltd.
87
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,10 +16,10 @@
1716
*
1817
**********************************************************************/
1918

20-
#ifndef ERRCODE_H
21-
#define ERRCODE_H
19+
#ifndef ERRCODE_H
20+
#define ERRCODE_H
2221

23-
#include "host.h"
22+
#include "host.h"
2423

2524
/*Control parameters for error()*/
2625
enum TessErrorLogCode {
@@ -81,11 +80,15 @@ class TESS_API ERRCODE { // error handler class
8180

8281
const ERRCODE ASSERT_FAILED = "Assert failed";
8382

84-
#define ASSERT_HOST(x) if (!(x)) \
85-
{ \
86-
ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", \
87-
__FILE__, __LINE__); \
88-
}
83+
#if defined __cplusplus
84+
# define DO_NOTHING static_cast<void>(0)
85+
#else
86+
# define DO_NOTHING (void)(0)
87+
#endif
88+
89+
#define ASSERT_HOST(x) (x) \
90+
? DO_NOTHING \
91+
: ASSERT_FAILED.error(#x, ABORT, "in file %s, line %d", __FILE__, __LINE__)
8992

9093
#define ASSERT_HOST_MSG(x, ...) \
9194
if (!(x)) { \
@@ -100,4 +103,5 @@ void set_global_loc_code(int loc_code);
100103
void set_global_subloc_code(int loc_code);
101104

102105
void set_global_subsubloc_code(int loc_code);
106+
103107
#endif

0 commit comments

Comments
 (0)