I wouldn't use WD-40 on my guns. About the only thing I use it for is to spray out rusty old outdoor pad locks occasionally.
I use a combination of different products to clean and lube my guns. The primary thing I use on my polymer pistols is Ballistol for overall cleaning. I also soak the barrels in a small jar of Hoppes #9 bore cleaner for an hour or more, because it makes pretty quick work of the carbon deposits, then I go over the barrel with more Ballistol afterward.
For lube, I have other products and methods... when I detail strip my pistols, I normally de-grease all of the steel parts from within the frame and slide using alcohol and/or acetone, then coat them with Dupont Dry Teflon lube, either completely or at least at their friction points. Then I put Super Lube grease, which is an odorless synthetic food grade lube that also contain PTFE (teflon) on those same parts or friction points. I also use that grease on my slide rails whenever I clean my guns. I don't use any of that PTFE-based stuff on the barrel though. I run patch cloths on a jag through the inside until clean and dry of Ballistol, then coat the outside of the barrel with a thin layer of Hoppes oil.
In between major detail strip operations like that, if I'm headed to the range or whatever, I may put a drop or two of Hoppes oil on the various contact points.
Aside from the particular cleaners or lubes I use, I found that having a proper cleaning rod, with properly sized bronze bore brushes and brass jag, make a huge difference in how clean I can get the barrel of a pistol or rifle. Using a plastic bore brush and just wiping the inside of the barrel with slotted patch cloths leaves a lot of stuff behind.