diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 5f9c28f397..0cebc4954a 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -2825,9 +2825,9 @@ const case nodetype of equaln,unequaln : begin - if is_voidpointer(right.resultdef) and (left.nodetype<>niln) then + if is_voidpointer(right.resultdef) then inserttypeconv(right,left.resultdef) - else if is_voidpointer(left.resultdef) and (right.nodetype<>niln) then + else if is_voidpointer(left.resultdef) then inserttypeconv(left,right.resultdef) else if not(equal_defs(ld,rd)) then IncompatibleTypes(ld,rd); diff --git a/tests/webtbs/tw41052.pp b/tests/webtbs/tw41052.pp new file mode 100644 index 0000000000..c62a455bc7 --- /dev/null +++ b/tests/webtbs/tw41052.pp @@ -0,0 +1,26 @@ +program project2; + +{$mode objfpc} +{$inline on} + +function Func1(S: PAnsiChar): SizeUInt; +begin + Result := 0; +end; + +function Func2(S: PAnsiChar): SizeUInt; inline; +begin + Result := Func1(S); + if S <> nil then S[Result] := #0; +end; + +function Func3(S: PAnsiChar): SizeUInt; inline; +begin + Result := Func1(S); + if Assigned(S) then S[Result] := #0; +end; + +begin + Func2(nil); // <-- OK + Func3(nil); // <-- Error: Incompatible types: got "PAnsiChar" expected "Pointer" +end.