Sorry for being slow to respond, everyone. However, I think the circumstances surrounding the first of the John Smith boys are going to remain a matter for speculation.
Which brings me to the second one, my great-grandfather. The most obvious reason for naming him John would have been in tribute to the first one, who died before the second one was born. However, my great-grandfather's upbringing seems to have been unusual...
My great-great-grandmother died 4 days after John was born. The 1861 and 1871 censuses have the family living in Saltcoats, Ayrshire. According to the 1881 census, John, aged 2, was living as a "boarder" in nearby Ardrossan with a Mrs Margaret McCormack, recorded as being a 60-year-old widow from Saltcoats. I haven't managed to identify any other members of the Smith family (5 sisters ranging in age from 9 to 20, and a 7-year-old brother, as well as my great-great-grandfather, who was in the merchant navy so may well have been at sea) anywhere in 1881, certainly not in Saltcoats or Ardrossan, so I've no idea where they went but they don't seem to have stayed together.
In 1891 John, now 12, was still living in Ardrossan with Margaret, surname now recorded as McCormick, described as 74 and unmarried, and John recorded as being her grandson. Margaret McCormick died at that address in 1898, single, at the recorded age of 84 according to the informant, apparently her daughter (also Margaret McCormick). Helpfully, the death record gives the names of the deceased's parents, whose origins I have found, but I've drawn a blank with the births of both Margarets.
I can understand John effectively being given up for adoption, but why place her with a woman old enough to be his grandmother and who appears not to have been a relation? I haven't found any connection between the Smiths and the McCormicks.
Whatever the circumstances, the story passed down to my mother and uncle was that John's father had been a "sea captain" (whatever that might mean - in fact, he was an able seaman), and that the family were descended from Clan MacLaine of Lochbuie, which is on the island of Mull off the west coast of Scotland near Oban. I doubt if that part of the story is true either, but historically the MacCormicks were a sept of Clan MacLaine, and whatever the actual truth - which I suspect I'll never find out - three successive generations of Smith sons descended from my great-grandfather have been given the middle name McCormick.
It's a fascinating pastime, but so frustrating!