Requires clauses in pfn conversions for generic lambdas

Ivan Sokolov sugrob9000aero@gmail.com
Sat Sep 12 00:01:00 GMT 2026


When a generic lambda has constraints (requires clause/concepts on type
parameters), those are applied to its operator(), of course. But it seems
no consideration was made as to whether they also apply to conversion to
pointer to function.

Clang says yes, and to me this seems like solid and useful behavior.

GCC seems not to apply them, which in some cases results in weird reports
of ambiguity:

	struct foo: decltype([]<std::integral I>()->I {}),
	            decltype([]<std::floating_point F>()->F {}) {};
	float(*pfn)() = foo{};
	// accepted by clang, gcc thinks the conversion is ambiguous

...and in others results in ICE:

	float(*pfn)() = []<std::integral I>()->I {};
	// soundly rejected by clang, ICE in gcc

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.

Maybe it's worth fixing in gcc? (And perhaps the standard, too. This
feels like defect report material.)
I can probably come up with a patch sometime if people agree.

Ivan


More information about the Gcc mailing list