In C++17 copy elision is mandatory for variable and return value constructors (as long as it doesn't involve type conversion) which results in AST that does not contain elidable constructors in their usual places. In order to provide construction contexts in this scenario we need to cover more AST patterns.
This patch makes the CFG prepared for these scenarios by:
- Adding two new construction context classes: CXX17ElidedCopyVariableConstructionContext and CXX17ElidedCopyReturnedValueConstructionContext. These are forks of SimpleVariableConstructionContext and ReturnedValueConstructionContext which contain the additional CXXBindTemporaryExpr when it's found in the AST. Additionally, ReturnedValueConstructionContext is renamed into SimpleReturnedValueConstructionContext. Finally, common abstract base classes are introduced: VariableConstructionContext and ReturnedValueConstructionContext.
- Allowing CFGCXXRecordTypedCall element to accept VariableConstructionContext and ReturnedValueConstructionContext as its context.
CXXBindTemporaryExpr is assumed to be present iff the object has non-trivial destructor. If the object has trivial destructor then CXXBindTemporaryExpr is not there, and the AST is pretty much indistinguishable from the simple case so we re-use SimpleVariableConstructionContext and SimpleReturnedValueConstructionContext. I'm not entirely sure that this is indeed the same case, but for the purposes of the analyzer, which is the primary user of construction contexts, this seems fine because when the object has trivial destructor it is not scary to inline the constructor. When the object requires non-trivial destruction, the new construction context is provided, and the analyzer bails out (with the hope of falling back to the pre-temporary-support behavior) for now - but more work seems to be necessary on the analyzer side to prevent it from crashing during actual analysis.