<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Clang rejects referencing local variable of class type to initialize template parameter in body of lambda defined in template"
href="https://bugs.llvm.org/show_bug.cgi?id=50583">50583</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang rejects referencing local variable of class type to initialize template parameter in body of lambda defined in template
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>davidfromonline@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>The following well-formed translation unit
```
struct integral_constant {
static constexpr auto value = 0;
};
template<int>
struct s {};
template<typename>
void function_template() {
[] {
constexpr auto x = integral_constant();
s<x.value>();
};
}
void f() {
function_template<void>();
}
```
is rejected by clang with the error message
```
<source>:12:5: error: variable 'x' cannot be implicitly captured in a lambda
with no capture-default specified
s<x.value>();
^
<source>:17:2: note: in instantiation of function template specialization
'function_template<void>' requested here
function_template<void>();
^
<source>:11:18: note: 'x' declared here
constexpr auto x = integral_constant();
^
<source>:10:2: note: lambda expression begins here
[] {
^
<source>:10:3: note: capture 'x' by value
[] {
^
x
<source>:10:3: note: capture 'x' by reference
[] {
^
&x
<source>:10:3: note: default capture by value
[] {
^
=
<source>:10:3: note: default capture by reference
[] {
^
&
1 error generated.
Compiler returned: 1
```
See it live: <a href="https://godbolt.org/z/a5Mjh8ojv">https://godbolt.org/z/a5Mjh8ojv</a>
A very similar translation unit,
```
struct integral_constant {
};
template<auto>
struct s {};
template<typename>
void function_template() {
[] {
constexpr auto x = integral_constant();
s<x>();
};
}
void f() {
function_template<void>();
}
```
is rejected for the same bogus reason.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>