TL;DR: Do not ever copy anything at all from SE if you are working on something important. There might be legal issues that I mention here. And for sure there are technical reasons, which I don't mention, for never copying from SE at all.
Nobody knows if there is any license for code posted before the "migration" to CC BY-SA 4.0 (International). Only a trial would settle the issue for sure.
SE used CC-BY-SA 3.0 Unported some time ago. And unilaterally changed it to CC BY-SA 4.0 (International). Which is a copyright infringement act in the opinion of some people and thus would void their previous 3.0 licenses.
Actually, it used a different version before 3.0. And also unilaterally changed to 3.0 back then. Another copyright infringement act in the opinion of some people.
It could be argued that SE lost the licenses to code posted before the change to 4.0. If so you'd be copying unlicensed code. Unless you copied it yourself before such change if so you'd had gotten a proper license which would still be valid.
To complicate matters, when you post something here you are granting SE two licenses. The 4.0 one. And this one from Terms of Service
and you grant Stack Overflow the perpetual and irrevocable right and
license to access, use, process, copy, distribute, export, display and
to commercially exploit such Subscriber Content, even if such
Subscriber Content has been contributed and subsequently removed by
you as reasonably necessary to, for example (without limitation):
- Provide, maintain, and update the public Network
- Process lawful requests from law enforcement agencies and government agencies
- Prevent and address security incidents and data security features, support features, and to provide technical assistance as it may be
required
- Aggregate data to provide product optimization
But that is a license granted to SE. There is no indication whatsoever that SE is granting us a license based on that. SE seems to be publishing only under CC-BY-SA 4.0 (International).
Since SE has done this more than once it is quite possible they'll do it again. So even code posted under 4.0 is not safe unless you keep tabs on Meta and SE's actions. We can't simply come here, copy code, and expect that everything has been managed properly on the licensing side.