I use some scientific computing code which calls Fortran routines from C++, which has suddenly started giving a warning under gcc 6. Here is the barebones issue:
Consider a Fortran subroutine mult
defined in mult.f90
:
subroutine mult(c)
complex*16 c
c = c * c
return
end
I call this from a C++ file test.cpp
:
#include <complex>
#include <iostream>
extern "C" void mult_(std::complex<double> *);
int main() {
std::complex<double> z (1,0);
mult_(&z);
std::cout << z << "\n";
return 0;
}
When I compile the files using g++-6 I get the following warning:
$ g++-6 -O3 -W -Wall test.cpp mult.f90 -flto -o test2
test.cpp:4:17: warning: type of ‘mult_’ does not match original declaration [-Wlto-type-mismatch]
extern "C" void mult_(std::complex<double> *);
^
mult.f90:1:1: note: ‘mult’ was previously declared here
subroutine mult(c)
^
mult.f90:1:1: note: code may be misoptimized unless -fno-strict-aliasing is used
The warning goes away if I do any of the following:
- Replace g++-6 (version I have is 6.2.0) with g++-5 (version 5.4.1)
- Compile without the
-flto
flag - Use double (instead of std::complex) and real*8 (instead of complex*16)
Should I be concerned, or is this a warning that I can ignore? In the former case, how can I solve the issue?