g++ -O2 -std=c++11 main.cpp
on
#include <cmath> using namespace std; int main() { hypot(0.5,0.5); return 0; }
will yield
In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\cmath:44:0,
from main.cpp:1:
c:\mingw\include\math.h: In function 'float hypotf(float, float)':
c:\mingw\include\math.h:635:30: error: '_hypot' was not declared in this scope
{ return (float)(_hypot (x, y)); }
^
The problem doesn't appear if I use -O0 or without -std=c++11
g++ -v :
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable
-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-l
ibs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --en
able-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
Confirmed. While I don't have time to follow it up, at present, I can reproduce this with
(where my foo.cpp is a copy of your sample source). Notice that the issue is a combination of any optimization level which permits function inlining, with any option which causes
__STRICT_ANSI__
to be defined; it isn't specific to-std=c++11
.I can guess that the problem is unwarranted occlusion of the prototype for
_hypot()
in the presence of__STRICT_ANSI__
, while still exposing an inline function implementation which requires it, but, as I say, I don't have time to pursue it at present. The work-around is to add-D__NO_INLINE__
to the compile time options, to hide the offending inline function implementation.My bad... We refiled this because we experienced it while performing release testing... https://sourceforge.net/p/mingw/bugs/2266/. Wasn't aware MinGW knew about it. Sorry.
(Searching, I'm told it can be fixed by opening the offending file in an editor, and changing _hypot to just hypot).
Fixed on branch "legacy", (which is the current base for active development), by commit [49761b]; this provides a clean, more mathematically robust reimplementation for the entire
hypot()
,hypotf()
, andhypotl()
family of functions, while removing the bogus inline reference.Related
Commit: [49761b]