tbs0178.pp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. { $OPT=-Sg}
  2. PROGRAM NoLabel; { this program compiles fine with TP but not with FP }
  3. type
  4. ptestobj = ^ttestobj;
  5. ttestobj = object
  6. constructor init;
  7. procedure test_self;
  8. end;
  9. const
  10. allowed : boolean = false;
  11. constructor ttestobj.init;
  12. begin
  13. if not allowed then
  14. fail;
  15. end;
  16. procedure ttestobj.test_self;
  17. function myself : ptestobj;
  18. begin
  19. myself:=@self;
  20. end;
  21. begin
  22. if myself<>@self then
  23. begin
  24. Writeln('problem with self');
  25. Halt(1);
  26. end;
  27. end;
  28. LABEL
  29. N1,
  30. N2,
  31. FAIL, { this is a reserved word in constructors only! - FP fails here
  32. }
  33. More; { label not defined - FP fails, but a warning is enough for that
  34. }
  35. { since label referenced nowhere }
  36. var ptest : ptestobj;
  37. self : longint;
  38. BEGIN
  39. new(ptest,init);
  40. if ptest<>nil then
  41. begin
  42. Writeln('Fail does not work !!');
  43. Halt(1);
  44. end;
  45. allowed:=true;
  46. new(ptest,init);
  47. if ptest=nil then
  48. begin
  49. Writeln('Constructor does not work !!');
  50. Halt(1);
  51. end
  52. else
  53. ptest^.test_self;
  54. N1: Write;
  55. N2: Write;
  56. FAIL: Write;
  57. self:=1;
  58. END.