[cfe-dev] PR27015 (variable template initialized with a generic lambda expresssion)

Akira Hatanaka via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 12 17:22:36 PDT 2016

I was wondering whether someone could answer a few questions about variable
templates. I'm trying to come up with a patch that fixes the crash
described in PR27015.


The crash happens when clang compiles a code that has a variable template
initialized with a generic lambda. For example,

$ cat test1.c

template<typename T> auto fn = [](auto a) { return a + T(1); };

template <typename X>
int func() {
  X a = 0x61;
  return 0;

int main() {

First question, is this legal c++14 code? I didn't find anything that
suggests it isn't legal, but I haven't found any code that uses variable
templates like this either other than the provided test case.

Second question, what would the closure type look like in this case? My
understanding is that the closure type for generic lambda without template
parameters looks like this:

class Class {
template<typename AT>
  AT operator()(AT a) { ... }

With template parameter, would it look like this?

template<typename T>
class Class {
template<typename AT>
  AT operator()(AT a) { return a + T(1); }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160412/5f417157/attachment.html>

More information about the cfe-dev mailing list