Closed
Description
struct A {
void operator()(int) {}
};
inline constexpr struct {
constexpr auto operator()(A fn) const
{
return [f{fn}](auto &&tpl)
noexcept(noexcept(&f))
{ return true; };
}
} error;
inline constexpr struct {
constexpr auto operator()(A fn) const
{
return [f{fn}](auto &&tpl)
// noexcept(noexcept(&f))
{ return true; };
}
} no_error;
int main() {
(void)error( A{} )(1); // $1
(void)no_error( A{} )(1); // $2
}
- clang trunk with flag
c++26
- https://godbolt.org/z/1EK6qf8Th
- see
no_error
anderror
function object, if I delete thenoexcept
clause then everything is OK. - clang tells me to capture
fn
, which is weird (sincefn
is never used in function body), but if I do so, clang accepts it. - if I change
f
inside thenoexcept
tofn
, then again, everything would be fine.
- see
clang rejects $1 it with:
<source>:8:15: error: variable 'fn' cannot be implicitly captured in a lambda with no capture-default specified
8 | return [f{fn}](auto &&tpl)
| ^
<source>:8:12: note: in instantiation of exception specification for 'operator()<int>' requested here
8 | return [f{fn}](auto &&tpl)
| ^
<source>:26:21: note: in instantiation of function template specialization '(anonymous struct)::operator()(A)::(anonymous class)::operator()<int>' requested here
26 | (void)error( A{} )(1);
| ^
<source>:6:31: note: 'fn' declared here
6 | constexpr auto operator()(A fn) const
| ^
<source>:8:12: note: lambda expression begins here
8 | return [f{fn}](auto &&tpl)
| ^
<source>:8:12: note: capture 'fn' by value
8 | return [f{fn}](auto &&tpl)
| ^
| fn
<source>:8:12: note: capture 'fn' by reference
8 | return [f{fn}](auto &&tpl)
| ^
| &fn
1 error generated.
but accepts $2.
Expected behavior
Accepts both of them.