c++papigcc-pedantic

Pedantic raising error when linking PAPI


I am trying to build some project that uses the PAPI 5.4.3.0 library, in an Arch Linux x86_64.

For simplicity sake, I reproduced the things that I don't understand in these two files:

A.cpp

#include "string.h"
#include "papi.h"

int main() {
} 

B.cpp

#include "papi.h"
#include "string.h"

int main() {
} 

When compiling it (to an object file) I get the following:

(1)$ g++ A.cpp -c -std=c++11
(2)$ g++ A.cpp -c -std=c++11 -pedantic
In file included from b.cpp:2:0:
/usr/include/papi.h:1021:27: error: declaration of ‘int ffsll(long long int)’ has a different exception specifier
int ffsll(long long lli); //required for --with-ffsll and used in extras.c/papi.c
                       ^
In file included from A.cpp:1:0:
/usr/include/string.h:524:26: error: from previous declaration ‘int ffsll(long long int) throw ()’
__extension__ extern int ffsll (long long int __ll)

(3)$ g++ B.cpp -c -std=c++11 -pedantic

Why does the -pedantic flag raises errors, but not warnings?(2)

Why does the 3rd run does not raises nothing (just by switching the includes)?


Solution

  • -pedantic enables full compatibility with C++ Standard and disables gcc extensions. So stuff which reported in this mode usually is an error.

    As for why changing order of includes changes the error, I can only guess. My best guess is that string.h defines certain macros which are checked in papi.h. Looking in it's source code might help.