[cfe-commits] Handle missing 'typename' in function template definitions

Richard Smith richard at metafoo.co.uk
Wed May 16 16:41:28 PDT 2012


On Wed, May 16, 2012 at 11:51 AM, Douglas Gregor <dgregor at apple.com> wrote:

>
> On May 15, 2012, at 6:12 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>
> Hi,
>
> The attached patch allows Clang to recover better from a missing
> 'typename' keyword in a function template definition:
>
> <stdin>:1:29: error: missing 'typename' prior to dependent type name
> 'T::type'
> template<typename T> void f(T::type) {}
>                             ^~~~~~~
>                             typename
>
> With this patch, we carry on disambiguating past such a situation. If we
> can't disambiguate the declaration in some other way, the absence of
> 'typename' is used to infer that we have a variable declaration. I've also
> extended the disambiguation code to inspect the token immediately after the
> parameter-declaration-clause to disambiguate (in the above case, the {token is used to disambiguate, and more generally we will also look for an
> exception-specification, ref-qualifier, cv-qualifier, etc., which cannot
> appear after a parenthesized initializer in a variable declaration).
>
> Does this seem like a reasonable approach?
>
>
> I like this approach. Just one trivial comment:
>
> +    else if (NextToken().is(tok::amp) || NextToken().is(tok::ampamp) ||
> +             NextToken().is(tok::kw_const) ||
> +             NextToken().is(tok::kw_volatile) ||
> +             NextToken().is(tok::kw_throw) ||
> +             NextToken().is(tok::kw_noexcept) ||
> +             NextToken().is(tok::l_square) ||
> +             isCXX0XVirtSpecifier(NextToken()) ||
> +             NextToken().is(tok::l_brace) || NextToken().is(tok::kw_try)
> ||
> +             NextToken().is(tok::equal))
>
> Please cache NextToken() here.
>

Done. r156963.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120516/45ad4957/attachment.html>


More information about the cfe-commits mailing list