Tested with fpc 3.3.1 trunk (as of 2022-Mar-12) and 3.2.2 stable.
Ubuntu 20.04 64-bit

Good compile time error checking is one of the wonderful things about
Pascal.  But some char array and shortstring assignments which are not
size compatible do not produce a compile error as expected.  Please
see below.

{$mode objfpc}{$H+}
type
  TCharArray8    = packed array[0..7] of Char;
  TCharArray9    = packed array[0..8] of Char;
  TShortString8  = string[8];

const
  StringConst8 = '12345678';
  StringConst9 = '123456789';

  CharArrayConst8a: TCharArray8 = '12345678';
  CharArrayConst8b: TCharArray8 = StringConst8;
  CharArrayConst8c: TCharArray8 = ('1','2','3','4','5','6','7','8');

  //CharArrayConst8d: TCharArray8 = '123456789';   //compile error as expected
  //CharArrayConst8e: TCharArray8 = StringConst9;  //compile error as expected
  //CharArrayConst8f: TCharArray8 =
('1','2','3','4','5','6','7','8','9'); //compile error as expected

  ShortStringConst8a: TShortString8 = '12345678';
  ShortStringConst8b: TShortString8 = StringConst8;
  ShortStringConst8c: TShortString8 = '123456789';   //did not get
expected compile error (bug?)
  ShortStringConst8d: TShortString8 = StringConst9;  //did not get
expected compile error (bug?)

var
  CharArrayVar8:   TCharArray8;
  CharArrayVar9:   TCharArray9;
  ShortStringVar8: TShortString8;

begin
  CharArrayVar8 := '12345678';
  CharArrayVar8 := StringConst8;
  CharArrayVar8 := ['1','2','3','4','5','6','7','8'];  //requires fpc 3.3.1
  CharArrayVar8 := CharArrayConst8c;

  //CharArrayVar8 := ['1','2','3','4','5','6','7','8','9']; //compile
error as expected
  CharArrayVar8 := '123456789';   //did not get expected compile error (bug?)
  CharArrayVar8 := StringConst9;  //did not get expected compile error (bug?)

  CharArrayVar8 := ShortStringVar8;
  ShortStringVar8 := CharArrayVar8;

  ShortStringVar8 := '12345678';
  ShortStringVar8 := CharArrayConst8a;
  ShortStringVar8 := TCharArray8(['1','2','3','4','5','6','7','8']);
//requires fpc 3.3.1

  ShortStringVar8 := '123456789';   //did not get expected compile error (bug?)
  ShortStringVar8 := CharArrayVar9; //did not get expected compile error (bug?)
  ShortStringVar8 :=
TCharArray9(['1','2','3','4','5','6','7','8','9']); //did not get
expected compile error (bug?) (requires fpc 3.3.1)

end;

Should I open a couple of bug reports?
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to