I'm pretty sure there is an error in Visual C ++ 2015, but I'm not 100% sure.
the code:
// Encoding: UTF-8 with BOM (required by Visual C++).
Result with g ++:
[H: \ scratchpad \ simple_text_io]
> g ++ --version | find "++"
g ++ (i686-win32-dwarf-rev1, Built by MinGW-W64 project) 6.2.0
[H: \ scratchpad \ simple_text_io]
> g ++ compiler_bug_demo.cpp
[H: \ scratchpad \ simple_text_io]
> run a
Process exit code = 0.
[H: \ scratchpad \ simple_text_io]
> _
Result with Visual C ++:
[H: \ scratchpad \ simple_text_io]
> cl / nologo- 2> & 1 | find "++"
Microsoft (R) C / C ++ Optimizing Compiler Version 19.00.23026 for x86
[H: \ scratchpad \ simple_text_io]
> cl compiler_bug_demo.cpp / Feb
compiler_bug_demo.cpp
compiler_bug_demo.cpp (8): warning C4566: character represented by universal-character-name '\ U00010437' cannot be represented in the current code page (1252)
[H: \ scratchpad \ simple_text_io]
> run b
Process exit code = 1.
[H: \ scratchpad \ simple_text_io]
> _
Is there any UB, and if not, which compiler behaves correctly?
Addendum:
The behavior does not change for both compilers if you use the lowercase Greek PI, "π", which is in BMP, so it does not matter.
source share