* give a compile-time error when trying to define a short/ansistring typed constant

containing unicode strings instead of producing unpredictable behaviour
    (mantis #16219)

git-svn-id: trunk@15240 -
This commit is contained in:
Jonas Maebe 2010-05-08 10:57:39 +00:00
parent 43033bacae
commit cddb2ffcae
7 changed files with 402 additions and 362 deletions

2
.gitattributes vendored
View File

@ -9668,6 +9668,8 @@ tests/webtbf/tw1599.pp svneol=native#text/plain
tests/webtbf/tw1599b.pp svneol=native#text/plain
tests/webtbf/tw16022.pp svneol=native#text/plain
tests/webtbf/tw16203.pp svneol=native#text/plain
tests/webtbf/tw16219.pp svneol=native#text/plain
tests/webtbf/tw16219a.pp svneol=native#text/plain
tests/webtbf/tw16234.pp svneol=native#text/plain
tests/webtbf/tw1633.pp svneol=native#text/plain
tests/webtbf/tw1642.pp svneol=native#text/plain

View File

@ -368,7 +368,7 @@ scanner_w_illegal_warn_identifier=02087_W_Illegal identifier "$1" for $WARN dire
#
# Parser
#
# 03291 is the last used one
# 03293 is the last used one
#
% \section{Parser messages}
% This section lists all parser messages. The parser takes care of the
@ -1310,6 +1310,11 @@ parser_e_no_paras_for_class_destructor=03291_E_Class destructors can't have para
parser_f_modeswitch_objc_required=03292_F_This construct requires the \{\$modeswitch objectivec1\} mode switch to be active
% Objective-Pascal constructs are not supported when \{\$modeswitch ObjectiveC1\}
% is not active.
parser_e_widestring_to_ansi_compile_time=03293_E_Unicodechar/string constants cannot be converted to ansi/shortstring at compile-time
% It is not possible to use unicodechar and unicodestring constants in
% constant expressions that have to be converted into an ansistring or shortstring
% at compile time, for example inside typed constants. The reason is that the
% compiler cannot know what the actual ansi encoding will be at run time.
#
# Type Checking
#

View File

@ -381,6 +381,7 @@ const
parser_e_no_paras_for_class_constructor=03290;
parser_e_no_paras_for_class_destructor=03291;
parser_f_modeswitch_objc_required=03292;
parser_e_widestring_to_ansi_compile_time=03293;
type_e_mismatch=04000;
type_e_incompatible_types=04001;
type_e_not_equal_types=04002;
@ -859,9 +860,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 56399;
MsgTxtSize = 56492;
MsgIdxMax : array[1..20] of longint=(
24,88,293,96,80,51,110,22,202,63,
24,88,294,96,80,51,110,22,202,63,
49,20,1,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -662,14 +662,21 @@ implementation
{ convert to the expected string type so that
for widestrings strval is a pcompilerwidestring }
inserttypeconv(n,def);
if not codegenerror then
if (not codegenerror) and
(n.nodetype=stringconstn) then
begin
strlength:=tstringconstnode(n).len;
strval:=tstringconstnode(n).value_str;
end
else
{ an error occurred trying to convert the result to a string }
strlength:=-1;
begin
{ an error occurred trying to convert the result to a string }
strlength:=-1;
{ it's possible that the type conversion could not be
evaluated at compile-time }
if not codegenerror then
CGMessage(parser_e_widestring_to_ansi_compile_time);
end;
end
else if is_constcharnode(n) then
begin

13
tests/webtbf/tw16219.pp Normal file
View File

@ -0,0 +1,13 @@
{ %fail }
{$h-}
const
aStrArray: array [0..0] of String = (
#$ffff' '
);
begin
end.

13
tests/webtbf/tw16219a.pp Normal file
View File

@ -0,0 +1,13 @@
{ %fail }
{$h+}
const
aStrArray: array [0..0] of String = (
#$ffff' '
);
begin
end.