Questions tagged [gcc-pedantic]

The pedantic option to gcc to forces ANSI-compatibility of code.

The -pedantic option of gcc is a stricter version of the related -ansi and -std= options, which specify C standard versions that should be complied to. Though these options disable non-compliant extensions, the -pedantic option goes further. Not only does it disable these extensions, it issues warnings for all instances of code non-compliance that the standard requires a diagnostic for, and rejects more non-compliant code than the other options alone.

There is also the -pedantic-errors option, issuing errors instead of warnings.

However, even this cannot detect or block every instance of ISO C non-compliance.

From the gcc manpage:

**-Wpedantic**
**-pedantic**
Issue all the warnings demanded by strict ISO C and ISO C++;
reject all programs that use forbidden extensions, and some
other programs that do not follow ISO C and ISO C++.  For ISO
C, follows the version of the ISO C standard specified by any
-std option used.

Valid ISO C and ISO C++ programs should compile properly with
or without this option (though a rare few require -ansi or a
-std option specifying the required version of ISO C).
However, without this option, certain GNU extensions and
traditional C and C++ features are supported as well.  With
this option, they are rejected.

-Wpedantic does not cause warning messages for use of the
alternate keywords whose names begin and end with __.
Pedantic warnings are also disabled in the expression that
follows "__extension__".  However, only system header files
should use these escape routes; application programs should
avoid them.

Some users try to use -Wpedantic to check programs for strict
ISO C conformance.  They soon find that it does not do quite
what they want: it finds some non-ISO practices, but not
all---only those for which ISO C requires a diagnostic, and
some others for which diagnostics have been added.

A feature to report any failure to conform to ISO C might be
useful in some instances, but would require considerable
additional work and would be quite different from -Wpedantic.
We don't have plans to support such a feature in the near
future.


Where the standard specified with -std represents a GNU
extended dialect of C, such as gnu90 or gnu99, there is a
corresponding base standard, the version of ISO C on which
the GNU extended dialect is based.  Warnings from -Wpedantic
are given where they are required by the base standard.  (It
does not make sense for such warnings to be given only for
features not in the specified GNU C dialect, since by
definition the GNU dialects of C include all features the
compiler supports with the given option, and there would be
nothing to warn about.)

**-pedantic-errors**
Give an error whenever the base standard (see -Wpedantic)
requires a diagnostic, in some cases where there is undefined
behavior at compile-time and in some other cases that do not
prevent compilation of programs that are valid according to
the standard. This is not equivalent to -Werror=pedantic,
since there are errors enabled by this option and not enabled
by the latter and vice versa.
29 questions
20
votes
2 answers

The difference between -pedantic-errors and -Werror=pedantic in gcc

What is the difference between using -pedantic-errors and -Werror=pedantic in gcc? According to the documentation of GCC there is a difference: -pedantic-errors Give an error whenever the base standard (see -Wpedantic) requires a diagnostic, in…
Supremum
  • 542
  • 7
  • 23
14
votes
2 answers

Error: initializer element is not computable at load time

I have a function that takes a struct, and I'm trying to store its variables in array: int detect_prm(Param prm) { int prm_arr[] = {prm.field1, prm.field2, prm.field3}; return 0; } But with gcc -Wall -ansi -pedantic-errors -Werror I get the…
zxcv
  • 7,391
  • 8
  • 34
  • 30
11
votes
3 answers

GCC Warns About Function Pointer to Object Pointer Cast

Clearly casting between function pointers and object pointers is undefined behaviour in the general sense, but POSIX (see: dlsym) and WinAPI (see: GetProcAddress) require this. Given this, and given the fact that such code is targeting a…
9
votes
2 answers

C - control reaches end of non-void function

I'm writing a threading program, and the pthread_create method requires a void* function. I'm getting the "control reaches end of non-void function" warning, and I understand why (because I don't have any official return statement)- my question is…
user3475234
  • 1,503
  • 3
  • 22
  • 40
8
votes
3 answers

What are the examples of non-ISO practices, which are not found by -pedantic?

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html : Some users try to use -Wpedantic to check programs for strict ISO C conformance. They soon find that it does not do quite what they want: it finds some non-ISO practices, but not all—only…
pmor
  • 5,392
  • 4
  • 17
  • 36
8
votes
2 answers

Ambiguous constructor taking std::reference_wrapper when compiling with -pedantic

I have a class with both a copy constructor and a constructor taking a std::reference_wrapper: #include #include class Class { public: Class() { std::cout << "Class()" << std::endl; } Class(Class const &)…
zennehoy
  • 6,405
  • 28
  • 55
6
votes
3 answers

Initialize struct members to 0 (gcc -Wextra)

I want to initialize all struct members to 0. Common solution is to make something like this: struct foo bar = {0} I create this example: #include struct Stru2 { int c; int d; }; struct Stru1 { int a; Stru2 b; }; int…
NiegodziwyBeru
  • 864
  • 1
  • 10
  • 19
3
votes
3 answers

How to traverse an array parameter as void pointer

I have similar "generic" procedure like qsort, which has a void pointer (pointing at an array) and also a function pointer parameter. This function should work on any type of array. Example: void do_something(void * array, int count, int size, void…
Aaron
  • 826
  • 10
  • 22
2
votes
2 answers

How to put variable as argument in system()

I am trying to include the sleep 1 command in bash in my .cpp file While system("sleep 1") works fine, I would like to change 1 into a const int or string const string t = "1"; string c = "sleep " + t; system(c); However, it seems like the…
appleline
  • 27
  • 4
2
votes
0 answers

Pedantic warning in use of G_DEFINE_BOXED_TYPE

I recently came across the following warning in one of my applications that uses the GLib: warning: ISO C prohibits argument conversion to union type [-Wpedantic] note: in definition of macro '_G_DEFINE_BOXED_TYPE_BEGIN' 2147 | …
2
votes
1 answer

C++98 pedantic errors when using fixed width integers

My company is moving from C slowly to C++98. C++98 is a superset of C so this shouldn't be a problem, but it is. Printing 64-bit fixed-width integers using printf does not work when used in combination with pedantic, warning flags, and specifying…
kill -9
  • 159
  • 1
  • 9
2
votes
0 answers

-Wno-pedantic ignored on older gcc

I have a C++ application where I am using zero-arguments-variadic macros. However, I don't really like the standard conforming solution posted here on SO in various answers, but rather keep the GCC specific ##__VAR_ARGS__. I'd like to catch as much…
flowit
  • 1,382
  • 1
  • 10
  • 36
2
votes
0 answers

What GCC parameters do I need in addition to -std and -pedantic-errors for portability?

So I used to think using -std=c11 and -pedantic-errors were enough to force gcc to only compile code that would also compile on other standard-compliant compilers (possibly on other platforms, assuming no platform-specific libraries are used), such…
Wingblade
  • 9,585
  • 10
  • 35
  • 48
2
votes
1 answer

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() { }…
yZaph
  • 169
  • 1
  • 10
2
votes
1 answer

gcc: fixing -pedantic "unnamed structure" warning

I'm trying to get some code from elsewhere (specifically, here), to compile without any warnings when gcc is given the -pedantic flag. The only problem is this bit of code: struct __attribute__ ((aligned(NLMSG_ALIGNTO))) { struct nlmsghdr…
Matthew Cline
  • 2,312
  • 1
  • 19
  • 36
1
2