_vanger_'s blog

By _vanger_, history, 18 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://mirror.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://mirror.codeforces.com/contest/1843/submission/210710990 and when choosing VC++17 it gave wrong answer on test 1: https://mirror.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://mirror.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?

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

»
18 months ago, # |
  Vote: I like it +9 Vote: I do not like it

Yes, this is some bug

for (auto& pr : segments)
    cin >> pr.first >> pr.second;

works just fine

cout << _MSC_FULL_VER << endl; output 191125547 which corresponds to 15.4.5 version. I dont know in which version this bug was removed.

»
18 months ago, # |
Rev. 3   Vote: I like it +9 Vote: I do not like it

Yes, this is a bug in version 15.3. It was removed in version 15.5, which is after the version used by Codeforces.