From: Roger Shimizu <rosh@debian.org>
Date: Fri, 21 Jan 2022 23:22:49 +0900
Subject: Fix ftbfs for c++17

Closes: #983968
---
 ast_java.h       | 8 ++++----
 generate_ndk.cpp | 5 +++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/ast_java.h b/ast_java.h
index ec0ccfd..dc33b56 100644
--- a/ast_java.h
+++ b/ast_java.h
@@ -19,7 +19,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <memory>
-#include <optional>
+#include <experimental/optional>
 #include <string>
 #include <variant>
 #include <vector>
@@ -161,7 +161,7 @@ struct ExpressionStatement : public Statement {
 struct Assignment : public Expression {
   Variable* lvalue;
   Expression* rvalue;
-  std::optional<std::string> cast = std::nullopt;
+  std::experimental::optional<std::string> cast = std::experimental::nullopt;
 
   Assignment(Variable* lvalue, Expression* rvalue);
   Assignment(Variable* lvalue, Expression* rvalue, std::string cast);
@@ -297,7 +297,7 @@ struct Method : public ClassElement {
   std::string comment;
   std::vector<std::string> annotations;
   int modifiers = 0;
-  std::optional<std::string> returnType = std::nullopt;  // nullopt means constructor
+  std::experimental::optional<std::string> returnType = std::experimental::nullopt;  // nullopt means constructor
   size_t returnTypeDimension = 0;
   std::string name;
   std::vector<Variable*> parameters;
@@ -327,7 +327,7 @@ struct Class : public ClassElement {
   int modifiers = 0;
   int what = CLASS;  // CLASS or INTERFACE
   std::string type;
-  std::optional<std::string> extends = std::nullopt;
+  std::experimental::optional<std::string> extends = std::experimental::nullopt;
   std::vector<std::string> interfaces;
   std::vector<ClassElement*> elements;
 
diff --git a/generate_ndk.cpp b/generate_ndk.cpp
index f0445f7..8c49408 100644
--- a/generate_ndk.cpp
+++ b/generate_ndk.cpp
@@ -21,6 +21,7 @@
 #include "aidl_to_cpp_common.h"
 #include "aidl_to_ndk.h"
 
+#include <experimental/optional>
 #include <android-base/logging.h>
 
 namespace android {
@@ -236,7 +237,7 @@ static std::string MethodId(const AidlMethod& m) {
 static void GenerateClientMethodDefinition(CodeWriter& out, const AidlTypenames& types,
                                            const AidlInterface& defined_type,
                                            const AidlMethod& method,
-                                           const std::optional<std::string> return_value_cached_to,
+                                           const std::experimental::optional<std::string> return_value_cached_to,
                                            const Options& options) {
   const std::string clazz = ClassName(defined_type, ClassNames::CLIENT);
 
@@ -454,7 +455,7 @@ void GenerateClientSource(CodeWriter& out, const AidlTypenames& types,
     const bool cacheable = !method->IsUserDefined() && method->GetName() == kGetInterfaceVersion &&
                            options.Version() > 0;
     const auto return_value_cached_to =
-        cacheable ? std::make_optional<std::string>(kCacheVariable) : std::nullopt;
+        cacheable ? std::experimental::make_optional<std::string>(kCacheVariable) : std::experimental::nullopt;
     GenerateClientMethodDefinition(out, types, defined_type, *method, return_value_cached_to,
                                    options);
   }
