https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102678
Bug ID: 102678 Summary: GCC fails to compile immediately invoked lambda inside fold expression Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: michael.gerhold at web dot de Target Milestone: --- The following code #include <variant> #include <iostream> #include <string> template<typename... T> void printAlternatives([[maybe_unused]] const std::variant<T...>& variant) { ([&]() { // holds_alternative<T>(variant); // <- enable to make it compile T element{}; std::cout << element << "\n"; }(), ...); } int main() { std::variant<std::string, int, float> variant; printAlternatives(variant); } does not compile and gives the following error message: error: operand of fold expression has no unexpanded parameter packs But the code does compile both on MSVC and Clang. Live example on compiler explorer: https://godbolt.org/z/zEqW4njW3