If you tell the compiler the codepage is UTF8 it will treat string constants as UTF16
That sounds like a crazy compiler

Bart's sentence was a little inaccurate.
The compiler treats string constants as UTF-8 if you tell it so. However our UTF-8 "hack" sets the default encoding only later at run-time. At compile time the default string encoding is still the system's codepage, for example cp1252. Thus the compiler converts UTF-8 -> cp1252 when assigning a constant. Later our "hack" changes the default string encoding and the wrongly converted cp1252 data is treated as UTF-8 -> error!
Remember however that the potential problem is only with constants. Variables have dynamic encoding info and assignment goes right always.
Summa summarum:
Do not define {$Codepage UTF8} and assign constants only to an AnsiString. Then everything works as magic.
Please also look at my LazUnicode unit and test program, attached in another thread.
You can see that I assign a constant to a temporary AnsiString also when {$ModeSwitch UnicodeStrings} is defined and String type maps to UnicodeString.
FPC also has a type unicodestring. So was it wrong for FPC to also define one ???
No, Delphi compatibility is important, they had to define it.
There is no problem if everybody knows the facts. However Unicode is confusing and complicated enough even without extra complications. Take the word "character", what does it mean in Unicode? At least the encodings should be called without ambiquity.
Unicode (unicodestring) can be a UTF-32, UTF-16 or UTF-8 string.
This kind of proves the confusion. Does "unicodestring" mean the Delphi's UTF-16 type or a string of Unicode in general?