I am trying to use the gcc compiler in Keil IDE for stm32f103 microcontroller. I am writing a relatively small project with a bit of template code and a few clean virtual classes. No fancy C ++ 11 stuff. So far so good.
When I compile with -w or -pedantic, compiling projects is just fine. But when I put -Wall, I have a compilation error in this part:
template <typename T, typename U> T & round(T & value, U roundStep) { UMBA_ASSERT(roundStep > 0); UMBA_STATIC_ASSERT( std::numeric_limits<T>::is_integer ); UMBA_STATIC_ASSERT( std::numeric_limits<U>::is_integer ); T temp = value / roundStep; T remainder = value - temp*roundStep; if(remainder < roundStep/2) { value = temp*roundStep; } else { value = (temp+1)*roundStep; } return value; }
UMBA_STATIC_ASSERT is a typical "static C statement":
#define UMBA_STATIC_ASSERT_MSG(condition, msg) typedef char umba_static_assertion_##msg[(condition)?1:-1] #define UMBA_STATIC_ASSERT3(X, L) UMBA_STATIC_ASSERT_MSG(X, at_line_##L) #define UMBA_STATIC_ASSERT2(X, L) UMBA_STATIC_ASSERT3(X, L) #define UMBA_STATIC_ASSERT(X) UMBA_STATIC_ASSERT2(X, __LINE__)
The funny thing is that I canβt even understand the error:
compiling common_functions.cpp... src/Common_Functions/common_functions.h: In function 'T& common_functions::round(T&, U)': ./src/Global_Macros/global_macros.h(99): warning: typedef 'umba_static_assertion_at_line_131' locally defined but not used [-Wunused-local-typedefs] #define UMBA_STATIC_ASSERT_MSG(condition, msg) typedef char umba_static_assertion_##msg[(condition)?1:-1] ./src/Global_Macros/global_macros.h(100): error: note: in expansion of macro 'UMBA_STATIC_ASSERT_MSG' ./src/Global_Macros/global_macros.h(101): error: note: in expansion of macro 'UMBA_STATIC_ASSERT3' ./src/Global_Macros/global_macros.h(104): error: note: in expansion of macro 'UMBA_STATIC_ASSERT2' src/Common_Functions/common_functions.h(131): error: note: in expansion of macro 'UMBA_STATIC_ASSERT'
It differs from a static assertion error, something like "error: size of array" umba_static_assertion_at_line_21 "negative". And, as far as I can tell, round functions are not even called anywhere else in the project.
Here are all the compiler options just in case; includes in the Keil folder, are automatically installed using the IDE:
-c -mcpu=cortex-m3 -mthumb -gdwarf-2 -MD -Wall -O0 -I./src -I./src/Modules_Config -I./src/CMSIS -I./src/SPL/inc -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -mcpu=cortex-m3 -IC:/Keil4.72/ARM/CMSIS/Include -IC:/Keil4.72/ARM/Inc/ST/STM32F10x -DUSE_STDPERIPH_DRIVER -DUSE_FULL_ASSERT -Wa,-alhms="./lst/*.lst" -o *.o
I'm not sure what to do with this.