[PATCH] Allow return type deduction for templates in delayed parsing mode.

Faisal Vali faisalv at yahoo.com
Tue Oct 29 17:59:47 PDT 2013

  Yes - I think it is an MSVC-compatible change.  MSVC does allow trailing return types which is not an issue with templates in either delayed-parsing or non-delayed-parsing mode.  It is return type deduction that becomes the issue (i.e. the template must be instantiated to deduce its return type).  Your example below does not require return type deduction.

  The reason it errors when delayed-parsing is turned off has nothing to do with return type deduction (in delayed parsing mode all late-parsed-instantiations are parsed and instantiated at the end of the translation unit - so when foo is parsed at the end of the TU, bar can be found.  not so with eager template parsing).

  >> rnk wrote:
  Are you sure this is an MSVC-compatible change? MSVC allows late specified return types, and does so while delaying the parsing of the body. Consider this test case, which cl accepts and clang -fno-delayed-template-parsing rejects:

  extern "C" int puts(const char *s);
  template <typename T>
  auto foo(T x) -> decltype(x) {
    return x;
  void bar() { puts("bar"); }
  int main() { return foo(0); }


More information about the cfe-commits mailing list