https://bugs.llvm.org/show_bug.cgi?id=45032
Bug ID: 45032
Summary: "lambda expression in default argument cannot capture
any entity" is not correct
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected]
// https://godbolt.org/z/mWxfE2
void g6(int = ([x=1]{ return x; })());
test.cc:2:16: error: lambda expression in default argument cannot capture any
entity
void g6(int = ([x=1]{ return x; })());
^
The declaration of "g6" is taken directly from the example code in
https://eel.is/c++draft/expr.prim.lambda#capture-9
The text says:
> Because local entities are not odr-usable within a default argument, a
> lambda-expression appearing in a default argument cannot implicitly or
> explicitly capture any local entity. Such a lambda-expression can still have
> an init-capture if any full-expression in its initializer satisfies the
> constraints of an expression appearing in a default argument.
Notice: any _local_ entity. GCC, MSVC, and ICC seem to implement the "any local
entity" wording correctly; only Clang rejects code like "g6".
The full test case from the Standard is:
void f2() {
int i = 1;
void g1(int = ([i]{ return i; })()); // error
void g2(int = ([i]{ return 0; })()); // error
void g3(int = ([=]{ return i; })()); // error
void g4(int = ([=]{ return 0; })()); // OK
void g5(int = ([]{ return sizeof i; })()); // OK
void g6(int = ([x=1]{ return x; })()); // OK (but Clang rejects it)
void g7(int = ([x=i]{ return x; })()); // error
}
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs