MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / astlambda

Method astlambda

test/testtokenize.cpp:7272–7449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7270 }
7271
7272 void astlambda() {
7273 // a lambda expression '[x](y){}' is compiled as:
7274 // [
7275 // `-(
7276 // `-{
7277
7278 ASSERT_EQUALS("x{(a&[( ai=", testAst("x([&a](int i){a=i;});"));
7279 ASSERT_EQUALS("{([(return 0return", testAst("return [](){ return 0; }();"));
7280
7281 // noexcept (which if simplified to always have a condition by the time AST is created)
7282 ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) noexcept(true) { a=i; });"));
7283 ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) mutable noexcept(true) { a=i; });"));
7284 ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) const noexcept(true) { a=i; });"));
7285
7286 // both mutable and constexpr (which is simplified to 'const' by the time AST is created)
7287 ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) const mutable { a=i; });"));
7288 ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) mutable const { a=i; });"));
7289 ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) const mutable noexcept(true) { a=i; });"));
7290 ASSERT_EQUALS("x{([( ai=", testAst("x([](int i) mutable const noexcept(true) { a=i; });"));
7291
7292 // ->
7293 ASSERT_EQUALS("{([(return 0return", testAst("return []() -> int { return 0; }();"));
7294 ASSERT_EQUALS("{(something[(return 0return", testAst("return [something]() -> int { return 0; }();"));
7295 ASSERT_EQUALS("{([cd,(return 0return", testAst("return [](int a, int b) -> int { return 0; }(c, d);"));
7296 ASSERT_EQUALS("{([return", testAst("return []() -> decltype(0) {};"));
7297 ASSERT_EQUALS("x{(&[=", testAst("x = [&]()->std::string const & {};"));
7298 ASSERT_EQUALS("f{([=", testAst("f = []() -> foo* {};"));
7299 ASSERT_EQUALS("f{([=", testAst("f = []() -> foo&& {};"));
7300 ASSERT_EQUALS("f{([=", testAst("f = [](void) mutable -> foo* {};"));
7301 ASSERT_EQUALS("f{([=", testAst("f = []() mutable {};"));
7302
7303 ASSERT_EQUALS("x{([= 0return", testAst("x = [](){return 0; };"));
7304
7305 ASSERT_EQUALS("ab{&[(= cd=", testAst("a = b([&]{c=d;});"));
7306
7307 // 8628
7308 ASSERT_EQUALS("f{([( switchx( 1case y++", testAst("f([](){switch(x){case 1:{++y;}}});"));
7309
7310 ASSERT_EQUALS("{(=[{return ab=",
7311 testAst("return {\n"
7312 " [=]() {\n"
7313 " a = b;\n"
7314 " }\n"
7315 "};\n"));
7316 ASSERT_EQUALS("{=[{return ab=",
7317 testAst("return {\n"
7318 " [=] {\n"
7319 " a = b;\n"
7320 " }\n"
7321 "};\n"));
7322 ASSERT_EQUALS("{(=[{return ab=",
7323 testAst("return {\n"
7324 " [=]() -> int {\n"
7325 " a=b;\n"
7326 " }\n"
7327 "}"));
7328 ASSERT_EQUALS("{(=[{return ab=",
7329 testAst("return {\n"

Callers

nothing calls this directly

Calls 2

buildMethod · 0.80
cppMethod · 0.80

Tested by

no test coverage detected