I suppose you would have to define “long-lasting protection”. If we’re talking a year or more storage, no I wouldn’t recommend WD40, but I can assure you, a shotgun bore sprayed until dripping wet with WD-40 and stored for 6 months will not rust if stored inside a controlled atmosphere. CorrosionX HD or LPS #2.is probably the best for long term and rough service storage.
I know this: I’ve been using WD-40 for 50 years for cleaning and lubricating firearms and I’ve never had it fail to do the job intended. Lots of other choices out there for sure, and I use them as well. The best “gun oil” I’ve found is a high performance transmission fluid:
https://www.swepcolube.com/products/swepco-714-heavy-duty-4c4-transmission-fluid/