Skip to content

[BUG] Mocking fails when a macro precedes a function definition #1092

@parmi93

Description

@parmi93

In our project, we have defined a macro to force function inlining using __attribute__((always_inline)), which is a fairly common practice — I’ve seen many projects use this technique.
The issue is that when Ceedling/CMock encounters a macro preceding a function declaration, it generates invalid mock files with invalid syntax.

temp2.h:

#define INLINE inline
int a; // Another bug: without this dummy line, Ceedling does not generate any mocking for bar()

INLINE int bar(void) // Ceedling fails mocking this function
{
    return 10;
}

mock_temp2.h:
Image

I tried to change this setting in project.yml from:

:cmock:
  :strippables:  ['(?:__attribute__\s*\([ (]*.*?[ )]*\)+)']

into (added |(INLINE)):

:cmock:
  :strippables:  ['(?:__attribute__\s*\([ (]*.*?[ )]*\)+)|(INLINE)']

However, in this case, a different issue arises: the linker complains that bar() is defined multiple times — once in temp2.h and once in mock_temp2.c

Example project:
ceedling_test.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions