My garage is heated but it's attic is not. The attic is accessible and could make a good location for a large air compressor - saves space & could muffle the noise. But the annual temperature swings in the attic are a concern.
Winter temps here can go down, at the extreme, to < -10 F (-23 C).
Summer highs might be less of a concern, but get into the 80s/90s (26/32) outside - probably > 100 F (37 C) in the attic.
Aside from whether extreme temps could be harmful to the motor or compressor pump itself, the tank is bound to get some condensation in it. I would plan to have a drain tube / valve plumbed in, but I wonder if frozen ice inside the compressor tank could cause an issue?
I checked a manufacturer's manual for a somewhat expensive compressor and it literally says nothing about operating temperature.
Reading around internet forums I get kind of a mixed impression - nothing that seems conclusive.
There are indeed some compressors used outside all the time - like at gas stations for filling tires. But those might have been purpose built for the conditions so I don't infer much about a standard workshop compressor from that.