diff --git a/.gitattributes b/.gitattributes index 26ae27300a..5c9a4f7d5e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13399,6 +13399,7 @@ tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain tests/test/units/variants/tvararrayofintf.pp svneol=native#text/plain tests/test/units/variants/tw26370.pp svneol=native#text/plain tests/test/units/variants/tw27044.pp svneol=native#text/plain +tests/test/units/variants/tw30546.pp svneol=native#text/plain tests/test/units/windows/twinrawinput32.pp svneol=native#text/plain tests/test/units/windows/twinrawinput64.pp svneol=native#text/plain tests/test/uobjc24.pp svneol=native#text/plain diff --git a/compiler/nld.pas b/compiler/nld.pas index 5f656e1cd0..a4966bf312 100644 --- a/compiler/nld.pas +++ b/compiler/nld.pas @@ -836,6 +836,7 @@ implementation { call helpers for variant, they can contain non ref. counted types like vararrays which must be really copied } else if (left.resultdef.typ=variantdef) and + not(is_const(left)) and not(target_info.system in systems_garbage_collected_managed_types) then begin { remove property flag to avoid errors, see comments for } diff --git a/tests/test/units/variants/tw30546.pp b/tests/test/units/variants/tw30546.pp new file mode 100644 index 0000000000..d20bacfe77 --- /dev/null +++ b/tests/test/units/variants/tw30546.pp @@ -0,0 +1,37 @@ +{ %opt=-gh } + +{$mode objfpc} +{$h+} +{$inline on} + +uses + variants; +var + vv: variant; + +function func: variant; inline; +begin + result:=vv; +end; + +function varconstinl(const v: variant): boolean; inline; +begin + result:=v='abc'; +end; + +function test: boolean; inline; +begin + result:=varconstinl(func); +end; + +procedure dotest; +begin + HaltOnNotReleased:=true; + vv:='abc'; + if not test then + halt(1); +end; + +begin + dotest; +end.