Caldera formation has been explained by magma withdrawal from a crustal reservoir, but little is known about the conditions that lead to the critical reservoir pressure for collapse. During an eruption, the reservoir pressure is constrained to lie within a finite range: it cannot exceed the threshold value for eruption, and cannot decrease below another threshold value such that feeder dykes get shut by the confining pressure, which stops the eruption. For caldera collapse to occur, the critical reservoir pressure for roof failure must therefore be within this operating range. We use an analytical elastic model to evaluate the changes of reservoir pressure that are required for failure of roof rocks above the reservoir with and without a volcanic edifice at Earth's surface. With no edifice at Earth's surface, faulting in the roof region can only occur in the initial phase of reservoir inflation and affects a very small part of the focal area. Such conditions do not allow caldera collapse. With a volcanic edifice, large tensile stresses develop in the roof region, whose magnitude increase as the reservoir deflates during an eruption. The edifice size must exceed a threshold value for failure of the roof region before the end of eruption. The largest tensile stresses are reached at Earth's surface, indicating that faulting starts there. Failure affects an area whose horizontal dimensions depend on edifice and chamber dimensions. For small and deep reservoirs, failure conditions cannot be achieved even if the edifice is very large. Quantitative predictions are consistent with observations on a number of volcanoes.