C++14 weird behavior

Правка en3, от xuanquang1999, 2018-01-10 15:34:10

I'm solving 27E — Number With The Given Amount Of Divisors. My code involved a function mul(a, b) that will return 1018 + 7 if multiplying a and b will lead to overflow, and min(1018 + 7, a * b) otherwise. I checked for overflow using the condition a*b div a != b.

When I submit my solution using C++14, it seemed that the overflow check failed, which lead to WA on test 5.

34068376

However, when I uncomment the if statement in the mul function (which, theoretically don't print anything out), it get accepted.

34068431

I resubmitted the WA code with C++11 and C++17 Diagnostics, and it get accepted too.

I don't know what happened here. I suspected that some kind of optimization from compiler caused this strange behavior, but unfoturnately I know nothing about compiler optimization. Can anyone give me a proper explanation about this strange behavior? Thanks in advance.

Теги c++ 14, strange behaviour

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский xuanquang1999 2018-01-10 15:34:10 4
en2 Английский xuanquang1999 2018-01-10 15:32:55 2 Tiny change: 'nd $min(10e{18}+7, a*' -> 'nd $min(10^{18}+7, a*'
en1 Английский xuanquang1999 2018-01-10 15:32:35 1070 Initial revision (published)