Compiler quirks:Some bugs and features looks weird but really exists

Правка en5, от zhengqingyuan, 2024-09-19 08:33:19

There are some bugs and features exists while compiling a c++ code,it looks weird but really exists on standard c++ compiler.I'll write down the bugs and features here to remind you to aware of them.

1.stl::vector:fail to use operator "=".

I was trying to implent the merge function of segment tree while solving the task,and the initial code is

here

and found that it will get WA on test #6 using the language C++14(GCC 6-32).Then I found out that the

code

might got wrong.That because the location of lc[u] changed after using lc.push_back() and the same as rc[u],so the operator "=" might not work.

The bug have been fixed since C++17(GCC 7-32),but if you compile your code using language C++ and the previous version before C++17(GCC 7-32),the bug still exists.

2.vector:Can vector be compiled by head file ?

I've participated on a school contest and found that a code with stl :: vector ran successfully without head file <vector>,after that,I made some testing and found something miraculous:

If the compiler is on Windows system (on codeforces,Dev c++ on Windows,etc),you can use <algorithm> instead of <vector> to compile stl :: vector,but if the compiler is on Linux system (Luogu,and so on),<algorithm> is unable to compile stl :: vector.Also, in Windows <iostream> is able to compile stl :: vector too.So,for participants,especially for Chinese who is willing to engage on Olympics in informatics,please be aware of this.

For more such bugs and features,you can reply to the comment and I'll put some of them that sometimes exists but not well-known here.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский zhengqingyuan 2024-09-19 08:34:25 69
en5 Английский zhengqingyuan 2024-09-19 08:33:19 89
en4 Английский zhengqingyuan 2024-09-18 10:05:50 18 Tiny change: 'ion before,the bug s' -> 'ion before `C++17(GCC 7-32)`,the bug s'
en3 Английский zhengqingyuan 2024-09-18 10:01:50 217
en2 Английский zhengqingyuan 2024-09-18 09:53:30 1644 (published)
en1 Английский zhengqingyuan 2024-09-16 17:13:55 285 Initial revision (saved to drafts)