In nature very few fish would live for any amount of time in only 40 gallons of water, basically not much more than a puddle.
One of the reasons they wouldn't , is that such a tiny volume of water would be subject to those volatile temp swings mentioned above.
Fish kills during sumner heat waves are common in thousands (even millions) of gallons, and common in small lakes in places like northern WI, in these days of drastic climatic deviations.
In the 90s I kept a 50 gal tank in my back yard in WI, where daily water temps would hit 80sF and night temps drop in the 50sF.
I found the only way I could keep a reasonably stable enough environment to maintain the fish I like, was to use my 1500 gal shaded pond as a sump.
Photos below

My outside set up theses days in Panama is similar.(below)
My 180 gal main tank, is set up under the shade of a patio roof, with only the 125 gal heavily planted sump/refugium set up in partial sun.
If the power goes out, shutting down the recirculating pump action between the two tanks, the sump overheats very quickly late morning.

So I use of water lilies in the sump as a natural way to add shade, helps by soaking up direct sun that would easily over heat it..

I found using water lilies to be an invaluable tool as a natural water temp regulator, even in my larger ponds in WI.
Below

Moving water also remains a tad cooler.
A smaller pond in the 2 videos below (about 500 gallons, in WI) in partial shade using lilies, and Hyacinth for added shading, and moving water to help stabilize temp
koi pond fractionation
GOPR6064