<div dir="ltr"><div>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.</div><div><br></div><div><a href="https://llvm.org/bugs/show_bug.cgi?id=27015" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=27015</a><br></div><div><br></div><div>The crash happens when clang compiles a code that has a variable template initialized with a generic lambda. For example,</div><div><br></div><div>$ cat test1.c</div><div><br></div>template<typename T> auto fn = [](auto a) { return a + T(1); };<br><br><div>template <typename X><br>int func() {<br>  X a = 0x61;<br>  fn<char>(a);<br>  return 0;<br>}<br><br></div><div>int main() {<br>  func<int>();<div>}<p></p><p></p></div></div><div>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.</div><div><br></div><div>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:</div><div><br></div><div>class Class {</div><div>template<typename AT></div><div>  AT operator()(AT a) { ... }</div><div>  ...</div><div>};</div><div><br></div><div>With template parameter, would it look like this?</div><div><br></div><div>template<typename T></div><div><div>class Class {</div><div>template<typename AT></div><div>  AT operator()(AT a) { return a + T(1); }</div><div>  ...</div><div>};</div></div><div><br></div></div>