[PATCH] D19175: Fix for PR27015 (variable template initialized with a generic lambda expression)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 26 14:20:04 PDT 2016
On Tue, Apr 26, 2016 at 1:55 PM, Akira Hatanaka via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> ahatanak added a comment.
>
> I'm looking for a way to avoid the assert in
> Sema::PerformDependentDiagnostics that is fired when a template parameter
> doesn't have a name.
>
> In order to avoid the assert, CXXRecordDecl::isDependentLambda() should
> return true for the old lambda class, and in order to do that, somehow I
> have to set KnownDependent to true in Sema::ActOnStartOfLambdaDefinition
> when the lambda is used to initialize a variable template.
>
> I can think of two ways to fix this:
>
> 1. Make changes in Sema::ActOnTypeParameter to call S->AddDecl(Param)
> regardless of whether Param has a name. This looks harmless to me because
> the list of Scope's decls is used just to see if a declaration belongs to a
> certain scope.
>
> 2. Add a field to Scope that indicates whether a variable template is
> being parsed.
>
I would expect this to go wrong in other contexts too. For instance:
"template<typename> void f(int a = []{ return 0; }()) {}"
Does this sound like a good idea or are there other ways to do what I'm
> trying to do?
This is going wrong in SemaLambda.cpp:818 -- it's trying to figure out
whether the lambda appears within a template, but gets the computation
wrong if no template parameters are in scope. (The decls_empty() check is
trying to distinguish between an explicit specialization scope and a "real"
template parameter scope.)
Ultimately, I think this is a bug in the parser -- it's using a single
template parameter scope for a multi-level template parameter list, and
also for the case of an explicit specialization. In the former case, there
should be multiple template parameter scopes, and in the latter case there
should be no scope. I don't think the reuse of the template parameter scope
for a multi-level list matters, but we shouldn't have a template parameter
scope at all if the only template headers are explicit specialization
headers.
You could change Parser::ParseTemplateDeclarationOrSpecialization to track
whether it's only seen explicit specialization 'template<>' headers, and
call 'TemplateParmScope.setFlags(0)' if so. Then remove the decls_empty()
check from SemaLambda.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160426/c488cd91/attachment.html>
More information about the cfe-commits
mailing list