_vanger_'s blog

By _vanger_, history, 11 months ago, In English

I noticed a strange behavior when choosing the Microsoft Visual C++ 17 language. Structured binding is handled incorrectly.

Let's be concrete. I tried to solve that problem: https://codeforces.com/contest/1843/problem/E and noticed that exactly the same code leads to different decisions on different compilers. Namely, it was accepted when choosing G++17 (as well as G++20, Clang++20): https://codeforces.com/contest/1843/submission/210710990 and when choosing VC++17 it gave wrong answer on test 1: https://codeforces.com/contest/1843/submission/210711015 A small investigation showed that the problem was in the lines when I filled a vector of pairs using structured binding:

vector<pair<int, int>> segments(m);
for (auto& [l, r] : segments)
    cin >> l >> r;

^ not OK

As one can see from this submission: https://codeforces.com/contest/1843/submission/210711251 elements of the vector are not filled with input values for some reason, and remain the default zeroes. The problem was only with the vector of pairs. Vector of ints is initialized properly:

vector<int> xs(q);
for (auto& x : xs)
    cin >> x;

^ OK

I want to add that I couldn't reproduce the bug on my version of MSVC++ (Version 17.5.3). The problem was only with the compiler on the server. Is it some known bug of the MSVC++ compiler used on Codeforces? If it is, are there some more that are commonly known?

Full text and comments »

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