View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0016219FPCCompilerpublic2010-04-07 07:442010-11-16 16:57
ReporterThierry Coq 
Assigned ToJonas Maebe 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
Platformi386OSWindowsOS VersionXP
Product Version2.4.1Product Build24077 
Target VersionFixed in Version2.6.0 
Summary0016219: String in const array of string does not compile
DescriptionThe following piece of code results in a compiler abort with the following message: Fatal: Compilation aborted.

const

  aStrArray: array [0..0] of String = (

    #$ffff' '

  );

The same string in a const, without the array, compiles:
const
  aStrArray: #$ffff' ';

If the $ffff is the last part of the string, it compiles?

Steps To ReproduceTake the piece of code above and put it in a simple program. Compile. The compilation will abort.

A Lazarus project reproducing the problem is attached.
Additional InformationThis was also tested as a bug on 2.3.1.
However in Linux, I was unable to reproduce the bug (FPC 2.4.0, Build 22279, 25-10-2009).

A work-around for me that worked was to declare a (long) list of string constants, each with a different name.

TagsNo tags attached.
FPCOldBugId
Fixed in Revision15240
Attached Fileszip file icon BugConstStringArray.zip [^] (424,109 bytes) 2010-04-07 07:44

- Relationships
has duplicate 0018140resolvedJonas Maebe Initialized variables string with utf8 

-  Notes
(0036514)
Bart Broersma (reporter)
2010-04-07 11:58

fpc 2.4.1 / Win9x

With {$H-} when compiling I get a warning:

strarray.pp(9,3) Warning: string "`~Z" is longer than "255"

writeln('>',aStrArray[0],'<') gives:
>`~Z # ,Á_
           P  \q?  ü £pDîZ 
                                            <¦_    P  Ó­)<
¦_  ü <

If you declare
const
  aStrArray: #$ffff' ';
no such warning is shown and writeln('>',aStr,'<') gives >? <

With {$H+} compiling fails and the compiler crashes:

Free Pascal Compiler version 2.4.1 [2010/03/12] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Win32 for i386
Compiling strarray.pp
Fatal: Compilation aborted
An unhandled exception occurred at $00402142 :
EAccessViolation : Access violation
  $00402142
  $004E2C33
  $004E2C43
  $004C95AA
  $004C5424
  $004C2553
  $004C492F
  $0042E324
  $0041117C
  $004017E6

Declaring a string as having #$FFFF in it, to me looks as if it is supposed to be a WideString, and #$FFFF being a WideChar?

Declaring the array as array[0..0] of WideString resolves the issue.

Fpc should however not crash on compiling if it is declared as array[0..0] of string.
(0037359)
Jonas Maebe (manager)
2010-05-08 13:02

The compiler now gives an error if you try to declare a short/ansistring typed constant containing wide/unicode strings.

The reason is that the compiler cannot convert a wide/unicode string into an ansi/shortstring at compile-time, since it does not know what the ansi encoding will be when the program is executed (and this ansi encoding can even be different every time it is executed).

Kylix does compile the example program, but it converts the #$ffff into #$ff#$20, which I think makes no sense and is a bug in Kylix.

- Issue History
Date Modified Username Field Change
2010-04-07 07:44 Thierry Coq New Issue
2010-04-07 07:44 Thierry Coq File Added: BugConstStringArray.zip
2010-04-07 11:58 Bart Broersma Note Added: 0036514
2010-05-08 13:02 Jonas Maebe Fixed in Revision => 15240
2010-05-08 13:02 Jonas Maebe Status new => resolved
2010-05-08 13:02 Jonas Maebe Fixed in Version => 2.5.1
2010-05-08 13:02 Jonas Maebe Resolution open => fixed
2010-05-08 13:02 Jonas Maebe Assigned To => Jonas Maebe
2010-05-08 13:02 Jonas Maebe Note Added: 0037359
2010-11-16 16:57 Jonas Maebe Status resolved => closed
2010-12-02 23:58 Jonas Maebe Relationship added has duplicate 0018140



MantisBT 1.2.12[^]
Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker