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.

0 REPLIES 0