Skip to content

Commit 5a98aa7

Browse files
committed
Fix g++ compiler warnings
1 parent cec894a commit 5a98aa7

File tree

7 files changed

+30
-17
lines changed

7 files changed

+30
-17
lines changed

example/add_parameterised_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ YT_TESTP (add, add_numbers, int16_t, int16_t, int32_t)
2121

2222
YT_TEST (add, add_must_fail)
2323
{
24-
YT_NEQ_SCALAR (add (65536, 1), 65537);
24+
YT_NEQ_SCALAR (add ((uint16_t)65534, 1), 65535);
2525
YT_END();
2626
}
2727

example/add_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ YT_TEST (add, add_two_positive_numbers)
2929

3030
YT_TEST (add, add_must_fail)
3131
{
32-
YT_NEQ_SCALAR (add (65536, 1), 65537);
32+
YT_NEQ_SCALAR (add ((uint16_t)65534, 1), 65535);
3333
YT_END();
3434
}
3535

example/basic_tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ YT_TEST (basic, scaler_tests_ints)
3333

3434
YT_TEST (basic, string_tests)
3535
{
36-
char* string1 = "Earth";
36+
const char* string1 = "Earth";
3737

3838
YT_EQ_STRING (string1, "Earth"); // Passes because string1 == "Earth"
3939
YT_NEQ_STRING (string1, "Mars"); // Passes because string1 != "Mars"

example/sensor_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool is_printing_complete_handler (int id)
6969

7070
// * `is_printing_complete.invokeCount` shows the number of times this mocked function was
7171
// called. Starting from 1.
72-
return (is_printing_complete_fake.invokeCount > stop_after_iteration);
72+
return (is_printing_complete_fake.invokeCount > (unsigned)stop_after_iteration);
7373
}
7474

7575
YT_TEST (printer, printer_success)

tests/basic_failures.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ YT_TEST (basic, scaler_tests_ints)
2828
YT_END();
2929
}
3030

31-
YT_TEST (basic, string_tests)
31+
YT_TEST (basic, string_tests)
3232
{
33-
char* string1 = "Earth";
33+
const char* string1 = "Earth";
3434

3535
YT_EQ_STRING (string1, "earth"); // Fails because string1 != "earth"
36-
YT_NEQ_STRING (string1, "Earth"); // Fails because string1 == "Earth"
36+
YT_NEQ_STRING (string1, "Earth"); // Fails because string1 == "Earth"
3737

3838
YT_END();
3939
}
4040

41-
YT_TEST (basic, memory_tests)
41+
YT_TEST (basic, memory_tests)
4242
{
4343
#define ARRAY_LEN(b) (sizeof (b) / sizeof (b[0]))
4444

4545
char buffer1[] = { 0, 1, 2, 3 };
46-
//char buffer2[] = { 0, 1, 2, 3 };
46+
// char buffer2[] = { 0, 1, 2, 3 };
4747
char buffer3[] = { 0, 1, 2, 4 };
4848

49-
YT_EQ_MEM (buffer1, buffer3, ARRAY_LEN (buffer1)); // Fails because buffer1 != buffer3.
50-
//YT_NEQ_MEM (buffer1, buffer2, ARRAY_LEN (buffer1)); // Fails because buffer1 == buffer2.
49+
YT_EQ_MEM (buffer1, buffer3, ARRAY_LEN (buffer1)); // Fails because buffer1 != buffer3.
50+
// YT_NEQ_MEM (buffer1, buffer2, ARRAY_LEN (buffer1)); // Fails because buffer1 == buffer2.
5151

5252
YT_END();
5353
}

tests/basic_passing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ YT_TEST (basic, scaler_tests_ints)
3131

3232
YT_TEST (basic, string_tests)
3333
{
34-
char* string1 = "Earth";
34+
const char* string1 = "Earth";
3535

3636
YT_EQ_STRING (string1, "Earth"); // Passes because string1 == string "Earth"
3737
YT_NEQ_STRING (string1, "Mars"); // Passes because string1 != "Mars"

yukti.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,16 @@ void yt_reset(); // MUST BE DEFINED BY THE USER OF THIS HEADER FILE.
289289
YT__DEFINE_FUNC_BODY (YT__COUNT_ARGS (__VA_ARGS__), rt, f, __VA_ARGS__)
290290

291291
// ----
292-
#define YT__DEFINE_FUNC_STRUCT(f) YT__STRUCT_TAG (f) YT__STRUCT_VAR (f) = { 0 }
292+
293+
// clang-format off
294+
#ifdef __cplusplus
295+
#define YT__ZEROED { }
296+
#else
297+
#define YT__ZEROED { 0 }
298+
#endif /* __cplusplus */
299+
// clang-format on
300+
301+
#define YT__DEFINE_FUNC_STRUCT(f) YT__STRUCT_TAG (f) YT__STRUCT_VAR (f) = YT__ZEROED;
293302

294303
#define YT__DEFINE_FUNC_BODY_VOID(n, f, ...) \
295304
void f (YT__FUNC_PARAMS_X (__VA_ARGS__)) \
@@ -380,7 +389,8 @@ static YT__TestRecord* YT__current_testrecord = NULL;
380389
static uint32_t YT__total_test_count = 0;
381390
static uint32_t YT__failed_test_count = 0;
382391

383-
static YT__TestRecord* YT__create_testRecord (char* testname, size_t test_count, size_t test_number)
392+
static YT__TestRecord* YT__create_testRecord (const char* testname, size_t test_count,
393+
size_t test_number)
384394
{
385395
assert (testname != NULL);
386396

@@ -457,7 +467,7 @@ static void YT__free_testRecord (YT__TestRecord* trecord)
457467
#define YT__teardown() (void)0
458468
#define YT__ec_init() (void)0
459469
#else
460-
#define YT_IN_SEQUENCE(n) for (unsigned i = 0; i < (n); i++)
470+
#define YT_IN_SEQUENCE(n) for (int i = 0; i < (n); i++)
461471

462472
#define YT_MUST_NEVER_CALL(f, ...) \
463473
do { \
@@ -916,11 +926,14 @@ static int YT__equal_string (const char* a, const char* b, int* i)
916926

917927
static int YT__equal_mem (const void* a, const void* b, unsigned long size, int* i)
918928
{
929+
uint8_t* ta = (uint8_t*)a;
930+
uint8_t* tb = (uint8_t*)b;
931+
919932
*i = 0;
920-
while (size-- && *(uint8_t*)a++ == *(uint8_t*)b++)
933+
while (size-- && *ta++ == *tb++)
921934
(*i)++;
922935

923-
return *(uint8_t*)--a == *(uint8_t*)--b;
936+
return *--ta == *--tb;
924937
}
925938

926939
/*

0 commit comments

Comments
 (0)