Bug 30929 - -pedantic-errors doesn't produce errors!
Summary: -pedantic-errors doesn't produce errors!
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2007-02-22 21:19 UTC by Tobias Burnus
Modified: 2023-12-04 10:13 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-03-18 18:05:25


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-02-22 21:19:51 UTC
Example:
...testsuite/gfortran.dg> gfortran -c -pedantic-errors c_by_val_4.f ; echo $?

c_by_val_4.f:14.22:

      CALL DOIT( %VAL( P ) ) ! { dg-warning "Extension: argument list fu
                     1
Warnung: Extension: argument list function at (1)
c_by_val_4.f:16.22:

      CALL DOIT( %VAL( P ) ) ! { dg-warning "Extension: argument list fu
                     1
Warnung: Extension: argument list function at (1)
0

Expected:
- Non-zero exit code
- "Error:" instead of "Warning:"

Have fun when fixing this as several "dg-do run" tests have -pedantic warnings, -no-pedantic does not exist, and dg.exp contains:

    set DEFAULT_FFLAGS " -pedantic-errors"
Comment 1 Tobias Burnus 2007-02-27 15:33:48 UTC
The same is true for -Werror.
Warnings still give an exit status code of zero.
Comment 2 Tobias Burnus 2007-02-27 23:33:40 UTC
> The same is true for -Werror.

I have to correct myself:
-Werror gives a non-zero exit status, but still writes "Warning:". I think gfortran should follow gcc by changing also the label from "Warning:" to "Error:" for -Werror.

-pedantic-errors seems to be difficult as it is hard to divide -Wall warnings from -pedantic warnings. The easiest way is probably to imply -Wall by -pedantic_errors (defined in flags.h as flag_pedantic_errors).
Comment 3 Manuel López-Ibáñez 2007-03-05 17:05:52 UTC
I am not sure if gfortran diagnostics are different, but... are you sure that particular warning is a pedantic warning and not simply an unconditional warning? AFAIK, pedantic-errors will turn only pedantic warnings into errors, other warnings will still be warnings unless -Werror.

Comment 4 Tobias Burnus 2007-03-05 18:08:59 UTC
> I am not sure if gfortran diagnostics are different,

I think gfortran handles the warnings quite different, not that I know much about the details of the C frontend.

> but... are you sure that particular warning is a pedantic warning and not 
> simply an unconditional warning?

primary.c:  if (x_hex && pedantic
primary.c-      && (gfc_notify_std (GFC_STD_GNU, "Extension: Hexadecimal "

This gives only an error with pedantic set (and -std=f95 or -std=f2003).

Otherwise, -pedantic is quite interwoven with the rest: options.c, e.g.:

  if (pedantic)
    {
      gfc_option.warn_ampersand = 1;
      gfc_option.warn_tabs = 0;
    }

No idea how to untangle -pedantic from -Wtabs or -Wampersand if -pedantic-errors has been given, but -Werror has not.

Silently accepting and ignoring it, seems not to be the right way. The simple solution is not to accept -pedantic-errors (and to point to -Werror) or to turn on -Werror for -pedantic-errors. Both are rather easy solutions - and feel a bit clumsy. It needs presumably quite a lot of work to support -pedantic-errors properly.

First and simpler step should be to change "Warning:" into "Error:" for -Werror to be in line with the C front end.
Comment 5 Manuel López-Ibáñez 2007-03-05 18:15:40 UTC
(In reply to comment #4)
> > I am not sure if gfortran diagnostics are different,
> 
> I think gfortran handles the warnings quite different, not that I know much
> about the details of the C frontend.
> 

Ah, OK. Then forget anything that I said.
Comment 6 Manuel López-Ibáñez 2007-07-04 13:08:57 UTC
(In reply to comment #4)
> 
> No idea how to untangle -pedantic from -Wtabs or -Wampersand if
> -pedantic-errors has been given, but -Werror has not.
>

What gfortran should do is that if pedantic enables Wtabs, then the warnings should be of the form:

if (pedantic && warn_tabs)
 pedantic("whatever");
else if (warn_tabs)
 warning("whatever");

pedantic() emits errors if -pedantic-errors, otherwise it emits warnings.
warning() emits errors if -Werror, otherwise it emits warnings.

I guess there would be similar functions in gfortran. (It would be great to integrate the diagnostics machinery but making things work in a similar way is already a step forward).
Comment 7 Manuel López-Ibáñez 2015-09-07 16:44:17 UTC
An update given the new diagnostics machinery:

* -Werror works as expected (comment #2)

* -pedantic-errors (-Werror=pedantic) should give errors for anything marked with -Wpedantic such as:

gfc_warning (OPT_Wpedantic, "Extension: backslash character at %C");

However, Fortran does not seem to use OPT_Wpedantic. You could use LangEnabledBy to enable with it whatever option you wish.
Comment 8 Harald Anlauf 2016-01-29 23:16:20 UTC
The following patch produces the desired error for the example
of comment #0:

--- gcc/fortran/primary.c       (revision 232904)
+++ gcc/fortran/primary.c       (working copy)
@@ -1698,7 +1698,9 @@
        }
     }
 
-  if (!gfc_notify_std (GFC_STD_GNU, "argument list function at %C"))
+  if (!gfc_notify_std (GFC_STD_GNU, "argument list function at %C") ||
+      (pedantic &&
+       !gfc_warning (OPT_Wpedantic, "Extension: argument list function at %C")))
     {
       m = MATCH_ERROR;
       goto cleanup;


% gfc-trunk -c -Werror=pedantic gcc/testsuite/gfortran.dg/c_by_val_4.f
gcc/testsuite/gfortran.dg/c_by_val_4.f:14:22:

       CALL DOIT( %VAL( P ) ) ! { dg-warning "Extension: argument list function" }
                      1
Error: Extension: argument list function at (1) [-Werror=pedantic]
gcc/testsuite/gfortran.dg/c_by_val_4.f:16:22:

       CALL DOIT( %VAL( P ) ) ! { dg-warning "Extension: argument list function" }
                      1
Error: Extension: argument list function at (1) [-Werror=pedantic]


A more general solution might be to extend gfc_notify_std to generally
handle extensions.
Comment 9 Dominique d'Humieres 2018-12-01 12:23:13 UTC
Since at least 4.8 '-pedantic -Werror' gives an error;

% gfortran /opt/gcc/work/gcc/testsuite/gfortran.dg/c_by_val_4.f -c -pedantic -Werror
/opt/gcc/work/gcc/testsuite/gfortran.dg/c_by_val_4.f:14:6:

       CALL DOIT( %VAL( P ) ) ! { dg-warning "Extension: argument list function" }
      1
Error: Unclassifiable statement at (1)
/opt/gcc/work/gcc/testsuite/gfortran.dg/c_by_val_4.f:16:6:

       CALL DOIT( %VAL( P ) ) ! { dg-warning "Extension: argument list function" }
      1
Error: Unclassifiable statement at (1)

but '-pedantic-errors' does not

% gfortran /opt/gcc/work/gcc/testsuite/gfortran.dg/c_by_val_4.f -c -pedantic-errors
/opt/gcc/work/gcc/testsuite/gfortran.dg/c_by_val_4.f:14:22:

       CALL DOIT( %VAL( P ) ) ! { dg-warning "Extension: argument list function" }
                      1
Warning: GNU Extension: argument list function at (1)
/opt/gcc/work/gcc/testsuite/gfortran.dg/c_by_val_4.f:16:22:

       CALL DOIT( %VAL( P ) ) ! { dg-warning "Extension: argument list function" }
                      1
Warning: GNU Extension: argument list function at (1)

AFAICT '-pedantic-errors' is not handled by the gfortran FE.

Note that '-pedantic' may change a warning to an error:

% gfortran /opt/gcc/work/gcc/testsuite/gfortran.dg/hollerith8.f90 -pedantic
/opt/gcc/work/gcc/testsuite/gfortran.dg/hollerith8.f90:6:17:

   call wrtout (9hHELLO YOU, 9)
                 1
Warning: Legacy Extension: Hollerith constant at (1)
/opt/gcc/work/gcc/testsuite/gfortran.dg/hollerith8.f90:6:15:

   call wrtout (9hHELLO YOU, 9)
               1
Error: Rank mismatch in argument 'iarray' at (1) (rank-1 and scalar)