[llvm-bugs] [Bug 45032] New: "lambda expression in default argument cannot capture any entity" is not correct

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 26 07:52:48 PST 2020


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: unassignedclangbugs at nondot.org
          Reporter: arthur.j.odwyer at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

// 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200226/28a2b31b/attachment.html>


More information about the llvm-bugs mailing list