OMNeT++/OMNEST Bug Tracker - OMNeT++
View Issue Details
0000832OMNeT++IDE / C++ developmentpublic2015-08-12 19:092017-02-13 12:30
woife 
rhornig 
lowminoralways
resolvedfixed 
Windows and Linux
4.6 
5.1pre3 
0000832: Adding -pedantic compiler option triggers warnings in OMNeT++ headers
I wanted to use the compiler option -pedantic in one of my projects.
But compiling the project with this options overflows to console window with lots of warnings generated by some OMNeT++ headers.

All of these warnings are of the same type (warning: extra ‘;’) and are triggered by only 2 places in the code:

Place 1: nedsupport.h
--------------------------

This file contains the definition of the namespace 'NEDSupport', which ends at the end of the file, and is terminated with a semicolon. This semicolon is not necessary, triggers a warning, and can be safely removed.

Place 2: onstartup.h
--------------------------

This is more difficult. I can describe why the warning triggers, but I don't know how to fix it.

Suppose you have a message file name MyMessages.msg with a message type called MyMessage. Compiling this file creates a C++ file called MyMessages_m.cc.

This file will contain the lines
Register_Class(MyMessage);
and
Register_ClassDescriptor(MyMessageDescriptor);

These macros are defined in 'regmacros.h' and both contain as their last statement the macro EXECUTE_ON_STARTUP which is defined in 'onstartup.h'.

The code in EXECUTE_ON_STARTUP defines a namespace which is again followed by a semicolon. Again, this semicolon is not necessary and can be removed.

However, this time this is not enough: When the Register_Class macro is expanded, the semicolon after Register_Class in the original C++ File (MyMessage_m.cc) will follow right after the namespace definition, where it triggers the same warning.

I don't know how to fix this. As a very dirty workaround, I have added the following statement at the end of EXECUTE_ON_STARTUP:
   struct MAKE_UNIQUE_WITHIN_FILE(dirty_workaround_for_compiler_warning)

This gets rid of the warning, and I can compile my code with -pedantic without a single warning. However, the intention of adding -pedantic is to write clean code, so adding dirty hacks is probably not a good way to shut down a warning :)

It hasn't triggered a warning with my code, but the macro EXECUTE_ON_SHUTDOWN has the same structure as EXECUTE_ON_STARTUP, so I guess changes for one should also be applied to the other.
To add the compiler option -pedantic, I added the following text in project settings->OMNeT++->Makemake->Options->Custom->Makefrag:

CXXFLAGS += -pedantic
No tags attached.
Issue History
2015-08-12 19:09woifeNew Issue
2015-10-12 09:28ammmar1988Issue cloned: 0000842
2017-02-13 12:30rhornigNote Added: 0001316
2017-02-13 12:30rhornigStatusnew => resolved
2017-02-13 12:30rhornigFixed in Version => 5.1pre3
2017-02-13 12:30rhornigResolutionopen => fixed
2017-02-13 12:30rhornigAssigned To => rhornig

Notes
(0001316)
rhornig   
2017-02-13 12:30   
Pragmas were added to mute expected warnings in OMNeT++ code.