mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-11-04 05:39:29 +01:00 
			
		
		
		
	An uninitialized function Result of a managed type needs special handling.
    When passing it as a var parameter a warning need to be emitted, since a user
    may expect Result to be empty (nil) by default as it happens with local vars
    of a managed type. But this is not true for Result and may lead to serious issues.
    The only exception is SetLength(Result, ?) for a string Result. A user always
    expects undefined contents of the string after calling SetLength(). In such
    case a hint need to be emitted.
+ Tests for this.
git-svn-id: trunk@40216 -
		
	
			
		
			
				
	
	
		
			28 lines
		
	
	
		
			525 B
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			525 B
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
{ %fail% }
 | 
						|
{ %opt=-Sew -vw -O- }
 | 
						|
 | 
						|
{
 | 
						|
  Test for correct emitting of warnings/hints for uninitialized variables of management types
 | 
						|
  See also tbf/tb0258.pp
 | 
						|
}
 | 
						|
 | 
						|
// This code must issue warnings "Function result variable of a managed type does not seem to be initialized".
 | 
						|
 | 
						|
{$mode objfpc}
 | 
						|
 | 
						|
procedure fvar(var a: ansistring);
 | 
						|
begin
 | 
						|
  setlength(a,100);
 | 
						|
  a[2]:='a';
 | 
						|
end;
 | 
						|
 | 
						|
function f: ansistring;
 | 
						|
begin
 | 
						|
  // Warning for the ansistring Result, since initial contents of the Result is undefined.
 | 
						|
  fvar(Result);
 | 
						|
end;
 | 
						|
 | 
						|
begin
 | 
						|
  f;
 | 
						|
end.
 |