I listed my Delphi version info as Update 2 in my original post. It would appear that they further enforced generic type constraints when casting. You can no longer cast a TObject descendant as a generic type T if T isn't constrained as a class type. However, I did find a work around using the RTTI.TValue construct, which has methods for doing generic casts based on TypeInfo data, as well as the ability to get and set the internal value as a generic type. Here's the code:
class function Atomic<T>.Initialize(var storage: T): T;
var
xInValue, xOutValue: TValue;
begin
if not assigned(PPointer(@storage)^) then begin
if PTypeInfo(TypeInfo(T))^.Kind <> tkClass then
raise Exception.Create('Atomic<T>.Initialize: Unsupported type');
Result := Atomic<T>.Initialize(storage,
function: T
begin
xInValue := GetTypeData(PTypeInfo(TypeInfo(T)))^.ClassType.Create;
xInValue.TryCast(TypeInfo(T), xOutValue);
Result := xOutValue.AsType<T>;
end);
end;
end; { Atomic<T>.Initialize }
I've attached another patch. I haven't been able to test this at run-time, but it does compile. I wonder if that will work?