<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60518>60518</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] unexpected error: reference to local variable 'X' declared in enclosing function 'Y'
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
cor3ntin
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rupprecht
</td>
</tr>
</table>
<pre>
d708a186b6a9b050d09558163dd353d9f738c82d (reverted in 74ce297045bac4bc475b8e762d2a1ea19bb16d3c) causes an unexpected compilation failure for this:
```
struct StringLiteral {
template <int N>
StringLiteral(const char (&array)[N])
__attribute__((enable_if(N > 0 && N == __builtin_strlen(array) + 1,
"invalid string literal")));
};
struct Message {
Message(StringLiteral);
};
void Func1() {
auto x = Message("x"); // Note: this is fine
// Note: "xx\0" to force a different type, StringLiteral<3>, otherwise this
// successfully builds.
auto y = [&](decltype(Message("xx"))) {};
// ^ fails with: repro.cc:18:13: error: reference to local variable 'array'
// declared in enclosing function 'StringLiteral::StringLiteral<3>'
(void)x;
(void)y;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVEuP4jgQ_jXFpTTIKeM8DhxoGE67fdnL7gk5dgW8cjvIdnrg368c6BnoGa1GipL4UY-vvq9Kp-SOgXkN6gWIzBhlyC4AEajdQk_5NMZ1nM7nyOaUF_1or2vbiFZXbd3XuuuFElZ0SrVVLa2VStpuaGRrWrII1EZ-55jZogvYrAxT14iV6rVZ9WbVqL7lpiZLumJddX1f1VYaoA6NnhIn1AGnwJczm-LDjG9n53V2Y8BBOz9FxmGMmE8ugdyA2IH4eNfi_szLlONkMv6VowvHP1zmqD1C83I7xcxvZ68zI8itCxlfQX69Hz3bALVmDCmjOelY8AHVOkZ9BepAvbyC2pW_m-nhoHOOrp8yHw7z3ZaD7j0f3ADUviLIrygQqAaqsSx3IHd4OPST89mFQ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