Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing "extra ';'" error in GCC when -pedantic is on

I'm building my program with -pedantic flag, which causes an extra ';' error (because of a third-party header using a few macros inconsistently; the error is not shown when -pedantic is off). I don't really feel like turning -pedantic off, and neither do I want to edit the header. Is there any way to suppress this exact error? Like a -Wno-annoying-semicolon-error compiler switch or something?

like image 253
Roman Dmitrienko Avatar asked Apr 20 '10 14:04

Roman Dmitrienko


2 Answers

You can suppress pedantic warnings for external headers like this:

//save compiler switches
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"

//Bad headers with problem goes here
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>

//restore compiler switches
#pragma GCC diagnostic pop
like image 191
Shital Shah Avatar answered Oct 19 '22 14:10

Shital Shah


Use -isystem rather then -I when passing include paths, then GCC won't warn you about system headers.

For any headers you maintain, just edit them.

like image 28
ideasman42 Avatar answered Oct 19 '22 14:10

ideasman42