OK, I've spent a long session on this this morning, and think the problem is solved.
First of all, I added the extra lines suggested by @
wsnipex, but the build still failed. Next I tried rebooting and going straight to run level 3 (Command line, no X). Here, the build succeeded. It also succeeded when I ran it from XFCE rather than Plasma. Now Plasma is known to be a bit of a resource hog, but I would have thought that I had enough horsepower for that not to be an issue! Or maybe not?
Once I had achieved a successful build - as previously noted - all subsequent builds were successful. At this point I cleared the cache (ccache -C as suggested by @abga), but this time the build succeeded again. I'm beginning to suspect that just as one successful build would produce subsequent success, so a failed build would also guarantee subsequent fails, due to the cache! I've therefore added ccache -C to my build script!
I've also spotted that 18.1 has been released. I've downloaded this, and it too now builds successfully!
I'm not sure what conclusions its possible to draw from all of this, other than that clearing the cache seems a good idea! But I think the problem is now solved
Thanks to all for your help and patience!
--
Pete