yongwhan's blog

By yongwhan, history, 4 years ago, In English

Hi guys,

Just a quick question, as I am quite puzzled about the verdict difference.

Those two codes are identical, but it passes in G++17 and fails in G++14.

G++14 Verdict

G++17 Verdict

Locally, those two seem to both produce -2 as an answer for the first test case for both G++14 and G++17.

I am guessing I made a trivial mistake somewhere.

Could you guys enlighten me with why it passes on one but not the other? I am guessing it could be due to using unsupported/undefined behavior in G++14.

Thanks a lot!

Yongwhan

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
4 years ago, # |
Rev. 6   Vote: I like it +13 Vote: I do not like it

EDIT: this is wrong, see comment below

I think it may be this compiler bug.

If you run the code in custom invocation with #define _GLIBCXX_DEBUG on the first line (before any includes) on g++ C++11, an error message is produced:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'
  what():  __gnu_cxx...
Runtime error: exit code is 3
=====
Used: 0 ms, 76 KB

This doesn't happen on g++ C++14 or g++ C++17 though, so I'm not completely sure if this is the cause. Note that g++ C++11 also outputs -7 (the wrong output).

Compiling with G++ 9.3.0 on my local machine with any C++ version and with all debugging flags and sanitizers enabled does not lead to any error and your code produces the right output. So I think your code is fine.

Also, it works fine with Clang++17 diagnostics.