Here are some corrosion tests that involve WD40 and other lubricants or protectants.
Brownell's - Birchwood Casey Sheath, Boeshield T-9, Break-Free LP, Break-Free Weapon Wipes, Brownells Cosmoline, Brownells Rust Preventive No. 2, Hoppe's Lubricating Oil, Rig Universal Grease, Tetra Gun Lubricant, Valvoline 5W-30, and WD-40.
The Gun Zone - Kleen Bore TW25-B, Break Free CLP, Break Free LP, Shooter's Choice Rust Prevent, Birchwood-Casey Sheath, Remington RemOil, Eezox, WD-40, Kano Kroil, 3-in-One Household Oil, Sandaro Industries' Bore Cote, Miltec-1, Sandaro Industries' Arms Cote
WD40 did very well at preventing corrosion. I agree it's not a very good lubricant, though, and it will apparently leave behind a residue when it dries, so it isn't good for the gun's internals.
I mostly use WD40 on things like garden tools, patio furniture, the BBQ grill (for the stand and other parts that don't get hot), the kid's bikes, storm door hinges, and anything else that's exposed to the elements. I just spray it on and spread it with a cloth over the entire metal surface.
For guns I use Breakfree CLP 90% of the time.