Page MenuHomePhabricator

[CFG] [analyzer] Add construction context for CXXBindTemporaryExpr.
ClosedPublic

Authored by NoQ on Feb 7 2018, 5:14 PM.

Details

Summary

This covers temporary constructors for which a destructor is necessary. It is necessary to support CXXTemporaryObjectExpr here, which is a "constructor in the middle of nowhere" expression like C() - it's a sub-class of CXXConstructExpr which we didn't even notice yet because it didn't appear in construction contexts we added support for in the previous patches, but it does commonly appear in CXXBindTemporaryExprs and failing to consume the construction context would trigger the construction context overwrite assertion.

Note that when the destructor is trivial, CXXBindTemporaryExpr is omitted, and in that case we don't provide any construction context yet. In such cases there's no trigger statement at all, for example the following code:

struct S {};

void foo() {
  S();
}

would produce the following AST:

`-FunctionDecl 0x7fea280366a0 <line:3:1, line:5:1> line:3:6 foo 'void ()'
  `-CompoundStmt 0x7fea28036d98 <col:12, line:5:1>
    `-CXXTemporaryObjectExpr 0x7fea28036c70 <line:4:3, col:5> 'S' 'void () noexcept' zeroing

... and that's it.

So in that case we'd have to make a special kind of construction context that merely conveys that we are sure that we are indeed constructing a simple temporary object because we were directly told to do so by the programmer. But that's another story.

Diff Detail

Event Timeline

NoQ created this revision.Feb 7 2018, 5:14 PM
This revision was not accepted when it landed; it landed in state Needs Review.Feb 14 2018, 7:15 PM
This revision was not accepted when it landed; it landed in state Needs Review.
Closed by commit rC325210: [CFG] Provide construction contexts for temproary objects. (authored by dergachev, committed by ). · Explain Why
Closed by commit rL325210: [CFG] Provide construction contexts for temproary objects. (authored by dergachev, committed by ). · Explain Why
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.