For the Sagrada Familia bit... YES, assuming we're not talking about this sort -which obviously would apply to women too! :))
If you intend to visit the Cathedral of Barcelona that's another matter, it's possibly the only church in Barcelona that does enforce a dress code at certain times of the day, as you can see in this sign posted at the door. For the rest of churches, monasteries etc. located here in Catalonia (ie. Montserrat, Santa Maria del Mar, Pedralbes, etc), there's normally no problem with the attire whether it's shorts or bare shoulders, again, assuming we're not talking Britney Spear's style -you know what I mean!