[PATCH] Sema: Do not allow template declarations inside local classes

David Majnemer david.majnemer at gmail.com
Wed Oct 9 02:56:13 PDT 2013


Members which are templates inside of local classes can still exist with my
patch, they cannot be written explicitly though:

For example:
int fun() { auto L = [](const auto& x, auto& y){ return x + y; }; }

Gives an -ast-dump with:
`-FunctionDecl 0x6c8c480 <<stdin>:1:1, col:79> fun 'int (void)'
[...snip...]
              |-CXXRecordDecl 0x6cd6490 <col:25> class definition
              | |-FunctionTemplateDecl 0x6cd6740 <<invalid sloc>, col:76>
operator()

Given that this can still happen I am not eager to remove the code that
made these constructs work better.

I am of the belief that if we choose to accept this particular extension,
it should be explicitly OK'd in a draft or draft of a standard.  EDG, GCC
and even MSVC all agree that this should not be permitted.  I suppose if we
really want to support this feature, we should at least issue a diagnostic
under -pedantic.

-- 
David Majnemer

On Wed, Oct 9, 2013 at 1:19 AM, Yunzhong Gao <
Yunzhong_Gao at playstation.sony.com> wrote:

>
>   This is essentially the same implementation as what I proposed a few
> weeks ago,
>   http://llvm-reviews.chandlerc.com/D575.
>   On that review, I was waiting to hear from Faisal who has started adding
> support
>   for local member templates to clang, and I am not sure if he needs this
> support
>   for any language extensions.
>
>   I feel that it is wrong to just remove tests without also removing
> relevant compiler
>   changes, because that leaves a feature in the compiler without any
> tests. e.g.,
>   If one wants to remove the following two tests, he/she should either
> revert r184903
>   or write some different tests.
>   test/PCH/cxx-local-templates.cpp
>   test/PCH/cxx1y-local-templates.cpp
>
> http://llvm-reviews.chandlerc.com/D1866
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131009/dd2030ce/attachment.html>


More information about the cfe-commits mailing list