Improve Format's handling of temporaries
authorGiuseppe Ottaviano <ott@fb.com>
Mon, 26 Jun 2017 21:42:31 +0000 (14:42 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 26 Jun 2017 21:51:50 +0000 (14:51 -0700)
commit2734e379f411f7d9757f9b8d13c020249a6c2dd6
tree2989cd8d638346cea6ccd68b683319b2b47f6f75
parenta198e71565a8e2500fdab9e54725926686992916
Improve Format's handling of temporaries

Summary:
`FormatValue` holds non-integral objects by reference, which
can cause subtle problems if a formatter is constructed with temporary
arguments and used beyond the expression that constructs it.

With this diff the arguments are perfectly forwarded into a tuple, so
the formatter will take ownership of the temporaries while holding
references to lvalues as before.

The only downside is that now `FormatValue` objects are constructed
every time the formatter is used, rather than only at formatter
construction. This should not be noticeable as those objects'
constructors should just take a reference to the argument.

Note that the format string is still held by reference, but this is
fine because it should almost always be a string literal.

Reviewed By: ericniebler

Differential Revision: D5317382

fbshipit-source-id: ef8355194b634d3751ef1ccca32dd1db29e27c48
folly/Format-inl.h
folly/Format.h
folly/test/FormatTest.cpp