[PATCH] Fix PR18792 - Bad diagnostic messages for std::enable_if_t uses

Stephan Tolksdorf st at quanttec.com
Wed Mar 12 11:14:51 PDT 2014


Hi rsmith,

Fix PR18792 - Bad diagnostic messages for std::enable_if_t uses

This patch improves the diagnostic messages for overloads disabled with
enable_if, in particular those where the failing typename enable_if<...>::type
lookup happens during the instantiation of an alias template like
std::enable_if_t.

Previously the diagnostic note for an overload disabled with std::enable_if_t
(or a similar alias template) only contained the location of the typename
enable_if<...>::type lookup and did not contain the location of the disabled
function overload, which could be quite annoying when you had many overloads.

This patch makes clang generate a note with the name and location of the
outermost alias template in the SFINAE context in which the enable_if<...>::type
lookup failed. Typically this location will be inside the source range for the
function template declaration, i.e. exactly where we want it. In the rare
circumstances where this is not the case, see e.g. the new test case with the
FIXME in overload-candidates.cpp, the implementation makes sure that the
diagnostic is placed at the disabled overload.

I'm not certain whether using the "disabled by %0" message even for template
aliases whose names don't start with "enable" or "disable" is optimal, but I'm
pretty sure that in the vast majority of cases the generated message should
be quite understandable  and certainly better than the one generated when
not using the enable_if logic. Though, if someone has a good idea for the
wording, it would be easy to use a different message for such aliases.

This patch also improves the source range highlighting for regular enable_if
uses and always prints out the fully qualified name of the enable_if template
(as was requested by a FIXME in SemaOverload.cpp).

http://llvm-reviews.chandlerc.com/D3061

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/SourceLocation.h
  include/clang/Sema/Sema.h
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  test/SemaTemplate/constexpr-instantiate.cpp
  test/SemaTemplate/overload-candidates.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3061.1.patch
Type: text/x-patch
Size: 18783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140312/e23f09df/attachment.bin>


More information about the cfe-commits mailing list