thread_local_unittest: Avoid invalid casts to polymorphic type.