AutosarC++18_10-A5.1.8ΒΆ

Lambda expressions should not be defined inside another lambda expression

Required inputs: IR

Rationale

Defining lambda expressions inside other lambda expressions reduces readability of the code.

Example
// $Id: A5-1-8.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
    #include <cstdint>
    void Fn1()
    {
        std::int16_t x = 0;
        auto f1 = [&x]() {

                auto f2 = []() {};   // Non-compliant
                f2();

                auto f4 = []() {};   // Non-compliant
                f4();

        };      // Non-compliant

        f1();
    }
    void Fn2()
    {
        auto f5 = []() {
            // Implementation
        }; // Compliant
        f5();
    }
See Also
  • none

Possible Messages

Key

Text

Severity

Disabled

nested_lambda

Lambda expressions should not be defined inside another lambda expression

None

False

Options