[PATCH] Improving printed template names in diagnostic messages

Richard Trieu rtrieu at google.com
Wed Mar 20 17:20:44 PDT 2013


Typically, template types are made canonical when deducing template arguments.  However, using canonical types also means diagnostic messages will have canonical types when sugared types would be preferred.  As an example:

#include <string>
#include <vector>
using std::vector;
using std::string;

template<typename T>
T getVector(T a) {
  return T();
}

void foo() {
  std::vector<std::string> V;
  int s = getVector(V);
}

produces the error:
error: no viable conversion from 'std::vector<std::basic_string<char>, std::allocator<std::basic_string<char> > >' to 'int'
  int s = getVector(V);
      ^   ~~~~~~~~~~~~

With this patch, it gives this more readable message:
error: no viable conversion from 'std::vector<std::string>' to 'int'
  int s = getVector(V);
      ^   ~~~~~~~~~~~~

In addition, this favors printing the parameter name instead of printing something like "type-parameter-0-0"

Changes made to template deduction:
1) Remove the type canonicalization steps
2) Remove assertions that checked for canonical types
3) Use the type as provided, or used the desugared type.
4) For some cases, fallback to using canonical types.

Other changes:
1) Change SubstTemplateTypeParmType to store the replacement type instead of using the canonical type.
2) Change AutoType to store the deduced type instead of using the canonical type
3) Canonicalize the types above in their Profile functions, as well as in TemplateArgument's Profile function
4) Fix up tests.

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

Files:
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplate.cpp
  lib/AST/ASTContext.cpp
  lib/AST/TemplateBase.cpp
  test/CodeGenObjCXX/encode.mm
  test/Misc/diag-template-diffing.cpp
  test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p1-0x.cpp
  test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3-0x.cpp
  test/CXX/temp/temp.arg/temp.arg.type/p2.cpp
  test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
  test/SemaTemplate/operator-template.cpp
  test/SemaTemplate/instantiate-declref.cpp
  test/SemaTemplate/instantiation-default-1.cpp
  test/SemaTemplate/instantiate-init.cpp
  test/SemaTemplate/default-expr-arguments.cpp
  include/clang/AST/Type.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D562.1.patch
Type: text/x-patch
Size: 25955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130320/2a0e3b01/attachment.bin>


More information about the cfe-commits mailing list