tstprocv.pp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. { %FAIL }
  2. { this compilation should fail
  3. because an ansitring should not be allowed
  4. as equivalent to a normal short string
  5. for procvars PM }
  6. {$mode fpc}
  7. {$H-}
  8. uses
  9. strings;
  10. Type
  11. type_error_proc = procedure (Const St : String);
  12. Const
  13. error_proc : type_error_proc = nil;
  14. has_errors : boolean = false;
  15. var
  16. st : string;
  17. ast : ansistring;
  18. pst : pchar;
  19. procedure string_error_proc(const err : string);
  20. begin
  21. {$ifdef DEBUG}
  22. writeln('String error proc: ',err);
  23. {$endif DEBUG}
  24. if err<>st then
  25. has_errors:=true;
  26. end;
  27. procedure ansistring_error_proc(const err : ansistring);
  28. begin
  29. {$ifdef DEBUG}
  30. writeln('Ansistring error proc: ',err);
  31. {$endif DEBUG}
  32. if err<>ast then
  33. has_errors:=true;
  34. end;
  35. procedure pchar_error_proc(const err : pchar);
  36. begin
  37. {$ifdef DEBUG}
  38. writeln('Pchar error proc: ',err);
  39. {$endif DEBUG}
  40. if strcomp(err,pst)<>0 then
  41. has_errors:=true;
  42. end;
  43. begin
  44. st:='direct short string';
  45. string_error_proc(st);
  46. ast:='direct ansistring';
  47. ansistring_error_proc(ast);
  48. pst:='direct short string';
  49. pchar_error_proc(pst);
  50. error_proc:=@string_error_proc;
  51. st:='short string via procvar';
  52. error_proc(st);
  53. error_proc:=@ansistring_error_proc;
  54. ast:='ansistring via procvar';
  55. error_proc(ast);
  56. error_proc:=@pchar_error_proc;
  57. pst:='pchar via procvar';
  58. error_proc(pst);
  59. if has_errors then
  60. begin
  61. Writeln('Wrong code is generated');
  62. halt(1);
  63. end;
  64. end.