The section on lambda captures ([expr.prim.lambda.capture]/5) states that
If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.
Consider the follow example:
#include <iostream> int main () { auto foo = 1234; auto bar = [foo](int foo) { std::cout << foo << '\n'; }; bar(4321); }
The latest GCC version (8.2.0 - released on July 26, 2018) has no diagnostic for this. Neither does latest Clang version (7.0.0 - released on Sep 19, 2018).
Should there be a diagnostic (error/warning) from these compilers (as mentioned in the reference) along the lines of:
// parameter and simple-capture have the same name
Godbolt Demo here
That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.
It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With