Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc -Wall introduces compiler error

Tags:

c++

gcc

keil

I'm trying to use gcc compiler in Keil IDE for stm32f103 microcontroller. I'm compiling a relatively small project with a bit of template code and a couple of pure virtual classes. No fancy C++11 stuff. So far so good.

When I compile with -w or -pedantic, project compiles just fine. But when I put -Wall I have 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 "C static assert":

#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 part 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 static assertion error which is something like 'error: size of array 'umba_static_assertion_at_line_21' is negative'. And, as far as I can tell, round function is not even called anywhere in the project.

Here are all compiler options just in case; includes to Keil folder are put there automatically by 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.

like image 800
Amomum Avatar asked May 27 '16 12:05

Amomum


People also ask

What is gcc compiler error?

The name of the assembler program with gcc is just as . So the error message tells you, that running the assembler fails, because the assembler executable contains an illegal instruction. This might really be an hardware error, meaning that the executable of the assembler is broken.

Why am I getting a compiler error?

A compile error happens when the compiler reports something wrong with your program, and does not produce a machine-language translation. You will get compile errors. Everybody does. Don't let them bother you.

How does gcc treat warning errors?

You can use the -Werror compiler flag to turn all or some warnings into errors. Show activity on this post. You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning. Unfortunately, in this case there isn't any specific option that covers that warning.


1 Answers

Check whether the error persists when the compiler is invoked from the command line. Some IDEs may parse the compiler's output correctly and mistake warnings for errors.

like image 106
feersum Avatar answered Oct 03 '22 00:10

feersum