When measured with the lens focused on the center of the field pointed at a flat test chart parallel to the sensor and both lenses set at f/2.8:
- The EF 50mm f/1.8 STM is slightly sharper at the center than the EF 40mm f/2.8 STM
- The EF 40mm f/2.8 STM is slightly sharper in the corners than the EF 50mm f/1.8 STM.
- The EF 40mm f/2.8 STM has less difference between the center and the edges.
- The EF 50mm f/1.8 STM has more difference between the center and the edges.
- The average sharpness of the entire field is practically the same for both lenses
When measured with the lens focused on the center of the field pointed at a flat test chart parallel to the sensor and both lenses are set at f/5.6:
- The EF 50mm f/1.8 STM and the EF 40mm f/2.8 STM are equally sharp in the center of the field
- The EF 50mm f/1.8 STM is slightly sharper at the edges and corners than the EF 40mm f/2.8 STM
- The EF 40mm f/2.8 STM suffers moderately more from astigmatism than the EF 50mm f/1.8 STM near the edges and in the corners
- Both lenses are moderately sharper in the center than they are on the edges and in the corners
All of the above observations were made with the camera and lens carefully manually focused on the center of the frame. The difference in autofocus performance from one camera body to the next of the same model, and from one example to the next of the same lens model could very well be greater than the measured differences shown above.
The "less sharpness" on the edges and corners when imaging a flat test chart may be because the lens has less absolute resolution in those parts of the field, or it may be that the lens is just sharpest on the edges and in the corners at a slightly closer distance to the camera than the edges of the flat test chart. If the latter is the case, carefully refocusing the lens so that the corners are at their sharpest would cause the center to be "less sharp" because the point of sharpest focus in the center would then be behind the surface of the flat test chart. This is due to what is known as field curvature.
Roger Cicala, the founder and chief lens guru at lensrentals, has talked a lot at times about field curvature, what it is, and how different field curvature shapes can affect how different lenses can affect different types of photos.
There's a good overview of field curvature at this article he wrote for DP Review
He talks about various 50mm lenses in this blog entry at lensrentals
Keep in mind that often he is comparing the measured differences of two different copies of the same lens model!
Not all EF 40mm f/2.8 STM lenses will test exactly the same. Not all EF 50mm f/1.8 STM lenses will test exactly the same. Sometimes the measured differences of one copy of one lens model and another copy of another lens model are closer than the tested differences of two copies of either one of the lens models.