Usually not. Some brokers will just stop the trade. Others will use the buy to cover all or part of the short, or use the short to sell off all or part of the long.
Technically, those brokers that will allow you to do it are supposed to get a letter from you specifying that you want a "boxed" postion.
I get around the restriction by either using different brokerages, or by using brokerages that maintain separate long and short sub-accounts within each account.
Hard work often pays off over time,
but laziness always pays off right now.