cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIde BUG – wrong behavior with __has_include(“xxx.h”)

mbarg.1
Senior II

STM32CubeIde Version: 1.17.0

Build: 23558_20241125_2245 (UTC)

To show this bug, project “bug31_STMCubeIde” has been generated from a well tested .ioc file.

Printf() is re-directed to UART3 enabling messages on serial STLink interface.

A “UserCode” directory, with “UserInclude.h” and “testInclude1.h” files, is added to file system, to include dir and code source.

testInclude1.h defines MY_DEFINE1 as true (1)

UserInclude.h has some conditional include :

/* testInclude1.h exist and is in include list - condition is true */

#if __has_include("testInclude1.h")

/* include will be executed and is shown correctly */

#include "testInclude1.h"

#endif /* __has_include */



/* testInclude2.h doen not exist in include list - condition is false */

#if __has_include("testInclude2.h")

/* include will not be executed and is shown correctly */

#include "testInclude2.h"

#endif /* __has_include */



that work as expected.

Than has some conditional define that show not as expected:



/* MY_DEFINE1 is defined as 1 in testInclude1.h - condition is true */

#if MY_DEFINE1

/* ERROR - MSG1 should look as executable define as previous condition was true */

#define MSG1 printf("testInclude1.h was included as expected\n");

#else /* MY_DEFINE1 */

/* ERROR - MSG1 should look as non executable define as previous condition was true */

#define MSG1 printf("testInclude1.h was NOT included as expected\n");

#endif /* MY_DEFINE1 */

MSG1 and MSG2 added to UART3 init code to double check that __has include is properly handled by compiler.

On terminal we have:

testInclude1.h was included as expected\n

testInclude1.h was NOT included as expected\n

If we move to main.c and look at MSG1 we see a wrong value; also if we ask to go to declaration, we get to wrong place.

This is a huge problem with large configurable projects as it leads to a waste of time by developers team; a fast solution would be very useful.

2 REPLIES 2
TDK
Guru

> testInclude1.h was included as expected\n

> testInclude1.h was NOT included as expected\n

Doesn't make sense. Your code prints MSG1 and MSG2, which should be the following:

testInclude1.h was included as expected
testInclude2.h was NOT included as expected

Is that what you see? Two lines about testInclude1.h doesn't make sense. You only print MSG1 once and MSG2 is about testInclude2.h.

 

If you feel a post has answered your question, please click "Accept as Solution".

Let me drive you step by step.

First, bug is in  STM32CubeIde, not in gcc or compiler or linked code.

That means we have wrong behaviour of IDE when we use __has_include().

After usage of __has_include(), IDE is unable to consider any #include with the file parameter of __has_include.

That means all #define inside @#include are lost and that propagate through all project.

Load project in Ide and look to what happen with and without __has_include.

Eventually, I can add some screenshot.

I have both linux and windows IDE, from version 12 to last (18) and alla have this problem. Probably it is Eclipse problem, not STM but only STM can lobby with Eclipse to get fixed.