Requires clauses in pfn conversions for generic lambdas
Discussion on C++ standard's handling of requires clauses in generic lambda pfn conversions, suggesting a CWG issue and a GCC PR for an ICE.
Following up on a discussion about C++ lambda conversion operators, Alex (Waffl3x) agrees that the standard might be lacking in its description of requires clauses for pointer-to-function conversions of generic lambdas. He suggests opening a Core Working Group (CWG) issue to clarify the standard and advises the original poster to file a bug report for an Internal Compiler Error (ICE) observed in GCC, after checking for duplicates.
- proposer
Agrees that the C++ standard may need clarification regarding requires clauses in generic lambda pfn conversions and advises filing a CWG issue and GCC PR.
“Yes I think you should open a CWG issue. And at minimum open a PR for the ICE in your first message. (Please do check if it is a duplicate first, I haven't done so yet.)”
- contributor
Observes that both Clang and GCC deviate from the standard regarding trailing return types in generic lambdas, allowing template parameter deduction.
“The standard [expr.prim.lambda.closure#12] seems silent on the matter, and the above examples make me think this paragraph was simply forgotten when wording was modified to account for constraints.”
Technical Tradeoffs
- Strict adherence to the current standard (even if ambiguous) vs. adopting compiler-specific extensions that offer more flexibility.
- Clarifying the standard via CWG is slow but provides a definitive answer; compiler-specific bug fixes are faster but may lead to inconsistencies.
- The interaction between generic lambdas, PFN conversion, and requires clauses is complex, requiring careful analysis to ensure correct and consistent behavior.
In Details
This thread discusses a subtle C++ language feature: the conversion of generic lambdas to function pointers (PFN). Specifically, it examines how requires clauses, introduced for C++20 concepts, interact with this conversion when a trailing return type is used. The participants note that current C++ standards (as of C++20) might not fully specify or might have overlooked the behavior in this specific scenario, leading to potential ambiguities or deviations between compilers like GCC and Clang. The discussion points towards a need for clarification from the C++ Core Working Group (CWG) and a…
- Generic lambda
- A C++ lambda expression that uses
autofor its parameter types, allowing it to accept arguments of different types, similar to a function template. - Pointer-to-function (PFN)
- A pointer that stores the address of a function.
- Requires clause
- A C++20 language feature used to specify constraints on template parameters, often associated with concepts.
- Trailing return type
- A C++11 feature allowing the return type of a function or lambda to be specified after the parameter list, using
-> type. - CWG
- C++ Core Working Group. The committee responsible for maintaining and evolving the C++ programming language standard.
- ICE
- Internal Compiler Error. An error condition within the compiler itself, indicating a bug in the compiler's implementation.