Merge "Add testcase for issue 35933"
diff --git a/tests/device/issue35933-lambda/jni/Android.mk b/tests/device/issue35933-lambda/jni/Android.mk
new file mode 100644
index 0000000..1be41e7
--- /dev/null
+++ b/tests/device/issue35933-lambda/jni/Android.mk
@@ -0,0 +1,7 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := issue35933-lambda
+LOCAL_SRC_FILES := issue35933-lambda.cpp
+LOCAL_CFLAGS += -std=gnu++0x
+include $(BUILD_EXECUTABLE)
diff --git a/tests/device/issue35933-lambda/jni/Application.mk b/tests/device/issue35933-lambda/jni/Application.mk
new file mode 100644
index 0000000..19b4698
--- /dev/null
+++ b/tests/device/issue35933-lambda/jni/Application.mk
@@ -0,0 +1,2 @@
+APP_ABI := all
+APP_STL := gnustl_shared
\ No newline at end of file
diff --git a/tests/device/issue35933-lambda/jni/issue35933-lambda.cpp b/tests/device/issue35933-lambda/jni/issue35933-lambda.cpp
new file mode 100644
index 0000000..9fa86df
--- /dev/null
+++ b/tests/device/issue35933-lambda/jni/issue35933-lambda.cpp
@@ -0,0 +1,46 @@
+#include <utility> // for std::forward
+#include <iostream>
+
+
+static int total = 0;
+static void add(int n)
+{
+ std::cout << "Adding " << n << std::endl;
+ total += n;
+}
+
+static void display(const char message[])
+{
+ std::cout << message << ": " << total << std::endl;
+}
+
+template <class Callable, typename... ArgTypes>
+void* Call(Callable native_func, ArgTypes&&... args) noexcept
+{
+ std::clog << "in Call" << std::endl;
+ return native_func(std::forward<ArgTypes>(args)...);
+}
+
+static void* test_lambda(int delta)
+{
+ std::clog << "in test_lambda" << std::endl;
+ return Call([=](int delta)
+ {
+ std::clog << "in lambda" << std::endl;
+ add(delta);
+ display("total");
+ return nullptr;
+ }, delta);
+}
+
+int main(int argc, char* argv[])
+{
+ std::clog << "start" << std::endl;
+ test_lambda(5);
+ std::clog << "after first call" << std::endl;
+ test_lambda(20);
+ std::clog << "after second call" << std::endl;
+ test_lambda(-256);
+ std::clog << "after third call" << std::endl;
+ return total != -231;
+}