header-checker: Downgrade to C++ 14

This commit switches the option to `-std=c++14` to avoid potential ODR
violations and fix the Mac build.

This commit downgrades from `-std=c++17` to `-std=c++14` because
"llvm/Support/RWMutex.h" from clang-r370808 will use `std::shared_mutex`
when `-std=c++17` is specified but LLVM/Clang prebuilts are built with a
different implementation.

Furthermore, Mac OS X 10.8 (or 10.9) does not support
`std::shared_mutex`.  Thus, there are availability errors when we are
building header-checker for Mac OS X:

    clang-r370808/include/llvm/Support/RWMutex.h:98:8:
    error: 'shared_mutex' is unavailable: introduced in macOS 10.12

Bug: 139945549
Test: OUT_DIR=out && \
      development/vndk/tools/header-checker/android/build-prebuilts.sh

Change-Id: Ic23fbdb67f7cd0700a3001c644485f7d8d0ee3e2
diff --git a/vndk/tools/header-checker/Android.bp b/vndk/tools/header-checker/Android.bp
index 65e2484..d22ac55 100644
--- a/vndk/tools/header-checker/Android.bp
+++ b/vndk/tools/header-checker/Android.bp
@@ -32,7 +32,7 @@
     cppflags: [
         "-fno-exceptions",
         "-fno-rtti",
-        "-std=c++17",
+        "-std=c++14",
     ],
 
     target: {
@@ -211,6 +211,7 @@
     ],
 
     shared_libs: [
+        "libLLVM_host",
         "libc++_host",
     ],
 
diff --git a/vndk/tools/header-checker/src/diff/header_abi_diff.cpp b/vndk/tools/header-checker/src/diff/header_abi_diff.cpp
index e0ead74..f482253 100644
--- a/vndk/tools/header-checker/src/diff/header_abi_diff.cpp
+++ b/vndk/tools/header-checker/src/diff/header_abi_diff.cpp
@@ -156,8 +156,9 @@
 static void ReadConfigFile(const std::string &config_file_path) {
   ConfigFile cfg = ConfigParser::ParseFile(config_file_path);
   if (cfg.HasSection("global")) {
-    for (auto &&[key, value] : cfg.GetSection("global")) {
-      bool value_bool = ParseBool(value);
+    for (auto &&p : cfg.GetSection("global")) {
+      auto &&key = p.first;
+      bool value_bool = ParseBool(p.second);
       if (key == "allow_adding_removing_weak_symbols") {
         allow_adding_removing_weak_symbols = value_bool;
       } else if (key == "advice_only") {
diff --git a/vndk/tools/header-checker/src/linker/header_abi_linker.cpp b/vndk/tools/header-checker/src/linker/header_abi_linker.cpp
index 618c209..802241c 100644
--- a/vndk/tools/header-checker/src/linker/header_abi_linker.cpp
+++ b/vndk/tools/header-checker/src/linker/header_abi_linker.cpp
@@ -20,6 +20,7 @@
 #include "utils/command_line_utils.h"
 #include "utils/header_abi_util.h"
 
+#include <llvm/ADT/Optional.h>
 #include <llvm/Support/CommandLine.h>
 #include <llvm/Support/raw_ostream.h>
 
@@ -401,7 +402,7 @@
 }
 
 bool HeaderAbiLinker::ReadExportedSymbolsFromVersionScript() {
-  std::optional<utils::ApiLevel> api_level = utils::ParseApiLevel(api_);
+  llvm::Optional<utils::ApiLevel> api_level = utils::ParseApiLevel(api_);
   if (!api_level) {
     llvm::errs() << "-api must be either \"current\" or an integer (e.g. 21)\n";
     return false;
@@ -415,7 +416,7 @@
 
   repr::VersionScriptParser parser;
   parser.SetArch(arch_);
-  parser.SetApiLevel(api_level.value());
+  parser.SetApiLevel(api_level.getValue());
   for (auto &&version : excluded_symbol_versions_) {
     parser.AddExcludedSymbolVersion(version);
   }
diff --git a/vndk/tools/header-checker/src/repr/symbol/version_script_parser.cpp b/vndk/tools/header-checker/src/repr/symbol/version_script_parser.cpp
index eecbfe5..274ecd4 100644
--- a/vndk/tools/header-checker/src/repr/symbol/version_script_parser.cpp
+++ b/vndk/tools/header-checker/src/repr/symbol/version_script_parser.cpp
@@ -17,6 +17,8 @@
 #include "repr/symbol/exported_symbol_set.h"
 #include "utils/string_utils.h"
 
+#include <llvm/ADT/Optional.h>
+
 #include <iostream>
 #include <memory>
 #include <regex>
@@ -94,28 +96,28 @@
 
     // Check introduced tags.
     if (utils::StartsWith(tag, "introduced=")) {
-      std::optional<utils::ApiLevel> intro = utils::ParseApiLevel(
+      llvm::Optional<utils::ApiLevel> intro = utils::ParseApiLevel(
           std::string(tag.substr(sizeof("introduced=") - 1)));
       if (!intro) {
         ReportError("Bad introduced tag: " + std::string(tag));
       } else {
         if (!has_introduced_arch_tags) {
           result.has_introduced_tags_ = true;
-          result.introduced_ = intro.value();
+          result.introduced_ = intro.getValue();
         }
       }
       continue;
     }
 
     if (utils::StartsWith(tag, introduced_arch_tag_)) {
-      std::optional<utils::ApiLevel> intro = utils::ParseApiLevel(
+      llvm::Optional<utils::ApiLevel> intro = utils::ParseApiLevel(
           std::string(tag.substr(introduced_arch_tag_.size())));
       if (!intro) {
         ReportError("Bad introduced tag " + std::string(tag));
       } else {
         has_introduced_arch_tags = true;
         result.has_introduced_tags_ = true;
-        result.introduced_ = intro.value();
+        result.introduced_ = intro.getValue();
       }
       continue;
     }
diff --git a/vndk/tools/header-checker/src/utils/api_level.cpp b/vndk/tools/header-checker/src/utils/api_level.cpp
index a04b9b4..d588e41 100644
--- a/vndk/tools/header-checker/src/utils/api_level.cpp
+++ b/vndk/tools/header-checker/src/utils/api_level.cpp
@@ -16,6 +16,8 @@
 
 #include "utils/string_utils.h"
 
+#include <llvm/ADT/Optional.h>
+
 #include <cassert>
 #include <string>
 
@@ -24,7 +26,7 @@
 namespace utils {
 
 
-std::optional<ApiLevel> ParseApiLevel(const std::string &api_level_str) {
+llvm::Optional<ApiLevel> ParseApiLevel(const std::string &api_level_str) {
   if (api_level_str == "current") {
     return FUTURE_API_LEVEL;
   }
diff --git a/vndk/tools/header-checker/src/utils/api_level.h b/vndk/tools/header-checker/src/utils/api_level.h
index 45e86e4..834dd6d 100644
--- a/vndk/tools/header-checker/src/utils/api_level.h
+++ b/vndk/tools/header-checker/src/utils/api_level.h
@@ -15,7 +15,8 @@
 #ifndef API_LEVEL_H_
 #define API_LEVEL_H_
 
-#include <optional>
+#include <llvm/ADT/Optional.h>
+
 #include <string>
 
 
@@ -29,7 +30,7 @@
 constexpr ApiLevel FUTURE_API_LEVEL = 10000;
 
 
-std::optional<ApiLevel> ParseApiLevel(const std::string &api);
+llvm::Optional<ApiLevel> ParseApiLevel(const std::string &api);
 
 
 }  // namespace utils
diff --git a/vndk/tools/header-checker/src/utils/api_level_test.cpp b/vndk/tools/header-checker/src/utils/api_level_test.cpp
index 74f0667..c1de948 100644
--- a/vndk/tools/header-checker/src/utils/api_level_test.cpp
+++ b/vndk/tools/header-checker/src/utils/api_level_test.cpp
@@ -25,11 +25,11 @@
   EXPECT_FALSE(ParseApiLevel(""));
   EXPECT_FALSE(ParseApiLevel("A"));
 
-  EXPECT_TRUE(ParseApiLevel("current").has_value());
-  EXPECT_EQ(FUTURE_API_LEVEL, ParseApiLevel("current").value());
+  EXPECT_TRUE(ParseApiLevel("current").hasValue());
+  EXPECT_EQ(FUTURE_API_LEVEL, ParseApiLevel("current").getValue());
 
-  EXPECT_TRUE(ParseApiLevel("16").has_value());
-  EXPECT_EQ(16l, ParseApiLevel("16").value());
+  EXPECT_TRUE(ParseApiLevel("16").hasValue());
+  EXPECT_EQ(16l, ParseApiLevel("16").getValue());
 }
 
 
diff --git a/vndk/tools/header-checker/src/utils/string_utils.cpp b/vndk/tools/header-checker/src/utils/string_utils.cpp
index 2dd97ad..4efcfbe 100644
--- a/vndk/tools/header-checker/src/utils/string_utils.cpp
+++ b/vndk/tools/header-checker/src/utils/string_utils.cpp
@@ -14,6 +14,8 @@
 
 #include "utils/string_utils.h"
 
+#include <llvm/ADT/Optional.h>
+
 #include <algorithm>
 #include <cctype>
 #include <cstdlib>
@@ -72,7 +74,7 @@
 }
 
 
-std::optional<int> ParseInt(const std::string &s) {
+llvm::Optional<int> ParseInt(const std::string &s) {
   const char *start = s.c_str();
   if (*start == '\0') {
     return {};
diff --git a/vndk/tools/header-checker/src/utils/string_utils.h b/vndk/tools/header-checker/src/utils/string_utils.h
index bcb8405..a42c9a5 100644
--- a/vndk/tools/header-checker/src/utils/string_utils.h
+++ b/vndk/tools/header-checker/src/utils/string_utils.h
@@ -15,7 +15,8 @@
 #ifndef STRING_UTILS_H_
 #define STRING_UTILS_H_
 
-#include <optional>
+#include <llvm/ADT/Optional.h>
+
 #include <string>
 #include <vector>
 
@@ -33,7 +34,7 @@
 std::vector<std::string_view> Split(std::string_view s,
                                     std::string_view delim_chars);
 
-std::optional<int> ParseInt(const std::string &s);
+llvm::Optional<int> ParseInt(const std::string &s);
 
 bool ParseBool(const std::string &s);
 
diff --git a/vndk/tools/header-checker/src/utils/string_utils_test.cpp b/vndk/tools/header-checker/src/utils/string_utils_test.cpp
index 4ad0074..98f25ca 100644
--- a/vndk/tools/header-checker/src/utils/string_utils_test.cpp
+++ b/vndk/tools/header-checker/src/utils/string_utils_test.cpp
@@ -83,14 +83,14 @@
   EXPECT_FALSE(ParseInt("0xa"));
   EXPECT_FALSE(ParseInt("16h"));
 
-  EXPECT_TRUE(ParseInt("0").has_value());
-  EXPECT_EQ(0, ParseInt("0").value());
+  EXPECT_TRUE(ParseInt("0").hasValue());
+  EXPECT_EQ(0, ParseInt("0").getValue());
 
-  EXPECT_TRUE(ParseInt("16").has_value());
-  EXPECT_EQ(16, ParseInt("16").value());
+  EXPECT_TRUE(ParseInt("16").hasValue());
+  EXPECT_EQ(16, ParseInt("16").getValue());
 
-  EXPECT_TRUE(ParseInt("-16").has_value());
-  EXPECT_EQ(-16, ParseInt("-16").value());
+  EXPECT_TRUE(ParseInt("-16").hasValue());
+  EXPECT_EQ(-16, ParseInt("-16").getValue());
 }