A potential divide by 0 is ignored by Intel C++ compiler ( no warning or remark displayed )

A potential divide by 0 is ignored by Intel C++ compiler ( no warning or remark displayed )

Please investigate a potential divide by 0 is ignored by Intel C++ compiler ( v13.x / W5 level of warnings / no warning or remark displayed ). I've done a verification with Microsoft C++ compiler and it reports:

...
double dX = 1.0L;
double dResult = (-dX + dX )/(-dX + dX );
...

..\Common\PrtTests.cpp(21076) : warning C4723: potential divide by 0

...

Thanks in advance.

6 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

If this compiles correctly, the result should be NaN, possibly set at compile time.

>>...If this compiles correctly, the result should be NaN, possibly set at compile time...

Thanks, Tim. It compiles.

I know that a result of the expression has to be equal to NaN and I'll do a verification if it sets at compile time. However, I really expected a warning or a remark from Intel C++ compiler especially when option /W5 is used.

I'll also do a verification with option /Wcheck.

Ritratto di iliyapolak

>>>double dResult = (-dX + dX )/(-dX + dX );>>>

If it compiles it should return a NAN.I used such a code to emulate a NaN returning to the caller.

Ritratto di jimdempseyatthecove

In the event that the compiler (version you have) is faulty and returns 0.0 as opposed to NaN, then try using "volatile double dX = 1.0L;"

IOW force the compiler to generate code to perform the calculation (as opposed to having the optimization pre-compute the result).

Jim Dempsey

www.quickthreadprogramming.com

>>>>A potential divide by 0 is ignored by Intel C++ compiler...
>>
>>In the event that the compiler (version you have) is faulty and returns 0.0 as opposed to NaN...

It doesn't return 0.0 and I didn't want to look or to take into account all the rest possible problems. Now, I confirm the problem and here are more details:

Note: Verified with versions 12.x and 13.x of Intel C++ compiler on 32-bit and 64-bit Windows platforms.

[ Test-Case 1 - /W5 /Wcheck options used ]
...
double dX = 0.0L;
dX = ( -1.0L + 1.0L )/( -1.0L + 1.0L );
dX = dX;
...

[ COMPILATION Output 1 ]
...
..\DivTestApp.cpp(24): warning #39: division by zero
dX = ( -1.0L + 1.0L )/( -1.0L + 1.0L );
...

[ Test-Case 2 - /W5 /Wcheck options used ]
...
double dX = 1.0L;
double dResult = ( -dX + dX )/( -dX + dX );
...

[ COMPILATION Output 2 ]

No Warning

Accedere per lasciare un commento.