Improve format member detection in llvm::formatv
authorPavel Labath <labath@google.com>
Thu, 8 Dec 2016 11:31:19 +0000 (11:31 +0000)
committerPavel Labath <labath@google.com>
Thu, 8 Dec 2016 11:31:19 +0000 (11:31 +0000)
commitfefefeb7f6a896946bba28a26b6ca7b98b54928d
tree77145417bafe07ad49bc0485ebe28538daabb2fb
parent371117e7a554e58b21ca88dfd53d74aca6d0a703
Improve format member detection in llvm::formatv

Summary:
The existing detection of a format member function has a couple of deficiencies:
- the member function does not get detected if one calls formatv with an lvalue,
  because the template parameter gets deduced as T&, which fails the is_class
  check.
- it also did not work if the function was called with a const variable because
  the template parameter would get deduced as const T&, again failing the
  is_class check.

This fixes the problem by stripping the references in the uses_format_member
template, to make sure the type is correctly detected as class. It also provides
specializations of the has_FormatMember template for const and non-const members
of the types in order to enable declaring the format member as a "const"
function. I have added tests that verify that formatv can be now called in these
scenarios. As some scenarios could not be verified at runtime (e.g. making sure
that calling a non-const format member on a const object does *not* compile), I
have also added some static_asserts which test the behaviour of the template
classes used internally by formatv().

Reviewers: zturner

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D27525

llvm-svn: 289040
llvm/include/llvm/Support/FormatVariadicDetails.h
llvm/unittests/Support/FormatVariadicTest.cpp