Jared
Jared

Reputation: 628

Force error on warning when compiling with ifx/ifort?

This is a remarkably trivial question, but clearly I am missing something: I just want compilation of the below Fortran program to fail when compiling with ifx/ifort if a warning is thrown. I have checked the documentation, but the -warn all,errors flag does not work as expected. What flags do I need to accomplish this?

! @file: warning.f90 
program warning_example
  implicit none
  integer :: x, y

  x = 10
  ! y is declared but never used, which should trigger a warning
  print *, 'Value of x:', x
end program warning_example

Checking the intel docs for -warn, where the syntax is described as

Syntax Linux: -warn [keyword[, keyword...]]

I would expect

ifort warning.f90 -warn all,errors

to error, however only

warning.f90(5): remark #7712: This variable has not been used. [Y] INTEGER :: x, y ------------------^

gets output and a binary is still is produced.

Similarly, compiling with ifx yields the same result. ifx is on my local system and is version ifx (IFX) 2025.0.4 while ifort is on a cluster I am using and is version ifort (IFORT) 2021.3.0.

Compilation fails as expected when calling something like

# gfortran --version --> GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
gfortran warning.f90 -Wall -Werror

with

enter image description here

Upvotes: 0

Views: 72

Answers (1)

It appears that the syntax you are trying is correct, but it does not what one would assume from the documentation for this specific kind of warning. For other warnings it does actually turn them into errors:

print *,x
end
> ifx -warn all,errors warn-implicit.f90 
warn-implicit.f90(1): error #6717: This name has not been given an explicit type.   [X]
print *,x
--------^
compilation aborted for warn-implicit.f90 (code 1)

It may be the intended behaviour, perhaps deserving a mention in the documentation, and it may be a bug. For the definitive answer, one would need confirmation from Intel (you can always ask at the official Intel forums). However, as also @francescalus mentioned, this kind of code with unused variables or arguments is so common, that it would fail to compile many codes. Perhaps too many.

Upvotes: 1

Related Questions