Skip to content

Commit

Permalink
Avoid brace initializers for scalars.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Jul 28, 2020
1 parent e83a125 commit f33d83d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/mimick.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void mmk_stub_destroy(struct mmk_stub *stub);
/**
* Convenience wrapper to get an addressable temporary object from a lvalue.
*/
# define mmk_val(Type, ...) &(mmk_literal(Type, {( __VA_ARGS__ )}))
# define mmk_val(Type, ...) &(mmk_literal(Type, {(__VA_ARGS__)}))

/**
* Defines a mock blueprint and typedef the Id to a function pointer type
Expand Down
8 changes: 6 additions & 2 deletions include/mimick/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ T mmk_literal<T, ID>::storage{0};

template <typename T>
T & mmk_assign(T & dst, T src) {
return dst = std::move(dst);
return dst = std::move(src);
}

template <typename T, size_t N>
Expand Down Expand Up @@ -72,7 +72,9 @@ va_list & mmk_assign(va_list & dst, va_list src) {
mmk_struct_initialize((mmk_literal<type, __COUNTER__>::storage), __VA_ARGS__)

# define mmk_literal(type, value) \
(mmk_assign(mmk_literal<type, __COUNTER__>::storage, value))
(mmk_assign(mmk_literal<type, __COUNTER__>::storage, (type) value))

# define mmk_default_value(type) type{0}

# else /* !defined __cplusplus */

Expand All @@ -82,6 +84,8 @@ va_list & mmk_assign(va_list & dst, va_list src) {

# define mmk_struct_literal(type, ...) ((type) { __VA_ARGS__ })

# define mmk_default_value(type) {0}

# endif

#endif /* !MMK_LITERAL_H_ */
4 changes: 2 additions & 2 deletions include/mimick/matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct mmk_matcher {

# define mmk_matcher_val_(Kind, Type, Val) (mmk_matcher_add(Kind, __COUNTER__), mmk_literal(Type, Val))
# undef mmk_any
# define mmk_any(Type) mmk_matcher_val_(MMK_MATCHER_ANY, Type, { 0 })
# define mmk_any(Type) mmk_matcher_val_(MMK_MATCHER_ANY, Type, mmk_default_value(Type))
# undef mmk_eq
# define mmk_eq(Type, Val) mmk_matcher_val_(MMK_MATCHER_EQ, Type, Val)
# undef mmk_ne
Expand All @@ -82,7 +82,7 @@ struct mmk_matcher {
# undef mmk_ge
# define mmk_ge(Type, Val) mmk_matcher_val_(MMK_MATCHER_GEQ, Type, Val)
# undef mmk_that
# define mmk_that(Type, Predicate) (mmk_matcher_add_fn(MMK_MATCHER_THAT, __COUNTER__, (void(*)(void))(Predicate)), mmk_literal(Type, { 0 }))
# define mmk_that(Type, Predicate) (mmk_matcher_add_fn(MMK_MATCHER_THAT, __COUNTER__, (void(*)(void))(Predicate)), mmk_literal(Type, mmk_default_value(Type)))

void mmk_matcher_init(int kind);
void mmk_matcher_add(enum mmk_matcher_kind kind, int counter);
Expand Down
2 changes: 1 addition & 1 deletion sample/strdup/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void test_error_case(void)
mmk_assert((mmk_fn) mock != MMK_MOCK_INVALID);

mmk_when(mock(mmk_any(size_t)),
.then_return = &(void *) { NULL },
.then_return = mmk_val(void *, NULL),
.then_errno = ENOMEM);

char *dup = my_strdup("foo");
Expand Down

0 comments on commit f33d83d

Please sign in to comment.