How to Get Gcc to Skip Errors, But Still Output Them

How to get gcc to skip errors, but still output them.

Up-to-date versions of GCC will attempt to skip certain errors where possible.

Say the body of foo(){... contains a const-violation. The translation unit will not produce an object file but any decent compiler will continue past this error into bar(){...

Other errors are unrecoverable. If you miss out some curly braces there's no reasonable guess that can be mades as to how to proceed.

gcc, make: how to disable fail on warning?

The trigger here is the -gnatpg (actually, the -gnatg): this is the "GNAT implementation mode (used for compiling GNAT units)". -gnatp means "suppress all checks".

I'm not sure of the full effect of -gnatg, though it certainly causes warnings to be treated as errors -- like -Werror -- at any rate while building the compiler itself; I think I remember seeing non-fatal warnings while building the RTS.

One possibility would be to compile just exp_ch5.adb by hand without -gnatg; the command you list was issued at gcc/, so

$ cd gcc
$ gcc -c -g -O2 -gnatp -gnata -nostdinc -I- -I. -Iada -I../../gcc/ada \
../../gcc/ada/exp_ch5.adb -o ada/exp_ch5.o

Then back up one level, and 'make' again.

This is a cross-compiler, so you won't (I hope!) need to repeat this for all three stages of a full build.

Disable all gcc warnings

-w is the GCC-wide option to disable warning messages.

Selectively remove a warning message using GCC

If you need that code to work portable then you should cast the argument to unsigned int, as the int type may have a different size than Int32 on some platforms.

To answer your question about disabling specific warnings in GCC, you can enable specific warnings in GCC with -Wxxxx and disable them with -Wno-xxxx.

From the GCC Warning Options:

You can request many specific warnings with options beginning -W, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default.

For your case the warning in question is -Wformat

-Wformat

Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified, and that the conversions specified in the format string make sense. This includes standard functions, and others specified by format attributes (see Function Attributes), in the printf, scanf, strftime and strfmon (an X/Open extension, not in the C standard) families (or other target-specific families). Which functions are checked without format attributes having been specified depends on the standard version selected, and such checks of functions without the attribute specified are disabled by -ffreestanding or -fno-builtin.

The formats are checked against the format features supported by GNU libc version 2.2. These include all ISO C90 and C99 features, as well as features from the Single Unix Specification and some BSD and GNU extensions. Other library implementations may not support all these features; GCC does not support warning about features that go beyond a particular library's limitations. However, if -pedantic is used with -Wformat, warnings will be given about format features not in the selected standard version (but not for strfmon formats, since those are not in any version of the C standard). See Options Controlling C Dialect.

How to suppress GCC warnings from library headers?

You may try to include library headers using -isystem instead of -I. This will make them "system headers" and GCC won't report warnings for them.

How to show 'preprocessed' code ignoring includes with GCC

I agree with Matteo Italia's comment that if you just prevent the #include directives from being expanded, then the resulting code won't represent what the compiler actually sees, and therefore it will be of limited use in troubleshooting.

Here's an idea to get around that. Add a variable declaration before and after your includes. Any variable that is reasonably unique will do.

int begin_includes_tag;
#include <stdio.h>
... other includes
int end_includes_tag;

Then you can do:

> gcc -E main -o out.c | sed '/begin_includes_tag/,/end_includes_tag/d'

The sed command will delete everything between those variable declarations.



Related Topics



Leave a reply



Submit