I was just at the Sagrada Familia in Barcelona this morning and there is no dress code. At least, no dress code was being enforced, and I didn't see any signs to the fact that there was any kind of dress code. Both men and women were wearing extremely high shorts, and the women were wearing short skirts and dresses. I was a little concerned because my shorts were just above the knee but I apparently was one of the more demure tourists today!! I guess as long as you're not in a bathing suit, they'll let you in. Not judging, just providing information in case anyone else had wondered what to wear. It's warm here in the summer and there's no reason to sweat to death just to go sightseeing!!
I was in Alicante a few weeks ago and I wore cargo shorts every day. There were plenty of people wearing shorts.
I remember a few years ago all the forums said don't wear jeans in Paris. When we got there, everybody was wearing jeans.
Wear what you want; I don't think anyone would be offended.
... SF is a "rare" religious building because, although mass is celebrated from time to time, it's mostly an attraction so far rather than a traditional church. Once it's finalised we'll see... *for those not knowing: it is a work in progress until 2026 or so!
... but in other churches, ie. The Cathedral, a dress code is enforced with more or less impetus, depending who's that turn guarding the entrances. In fact, at the Cathedral -like I've already mentioned in other posts in this forum- there are signs indicating this: http://tinypic.com/r/2urletf/8 (sorry for bad quality, made with phone in late afternoon!)
A follow-up question to the posted comments: If mass is not regularly celebrated in this church, is it open for tours on Sunday mornings? In attempting to purchase tickets on-line, I didn't see any indication of the church being closed at such times.
The church, where regular masses are held is accessible by parishioners (tourists just can't tromp in and out) by a separate entrance on the side of the Sagrada Familia. You can look down (I think I recall thru glass) into the local church from the main inside area of the Sagrada Familia.