[c++ build] suppress deprecation warnings

With newer version of Xcode (at least starting with version 13.2.1),
building Kudu on macOS produces many warnings because of C++17-related
deprecations, so it's not easy to spot warnings attributed to updates
in the local workspace.  This patch addresses the issue, adding pragmas
to disable deprecated declarations where appropriate.

In addition, this patch also silences warnings related to usage of
the deprecated Kudu API in src/kudu/client/schema.cc (it's used just
in the library implementation, so it's not a big deal).  I also took the
liberty to replace include guards with 'pragma once' and address
some of clang-tidy's recommendations in a few affected files.

Change-Id: I069a0680b4bc981b311374cc08bb950578db0dd0
Reviewed-on: http://gerrit.cloudera.org:8080/19202
Tested-by: Kudu Jenkins
Reviewed-by: Yifan Zhang <chinazhangyifan@163.com>
Reviewed-by: Attila Bukor <abukor@apache.org>
diff --git a/src/kudu/client/schema.cc b/src/kudu/client/schema.cc
index 203f360..1acb290 100644
--- a/src/kudu/client/schema.cc
+++ b/src/kudu/client/schema.cc
@@ -228,7 +228,6 @@
 Status KuduColumnStorageAttributes::StringToEncodingType(
     const string& encoding,
     KuduColumnStorageAttributes::EncodingType* type) {
-  Status s;
   string encoding_uc;
   ToUpperCase(encoding, &encoding_uc);
   if (encoding_uc == "AUTO_ENCODING") {
@@ -246,16 +245,15 @@
   } else if (encoding_uc == "GROUP_VARINT") {
     *type = KuduColumnStorageAttributes::GROUP_VARINT;
   } else {
-    s = Status::InvalidArgument(Substitute(
+    return Status::InvalidArgument(Substitute(
         "encoding type $0 is not supported", encoding));
   }
-  return s;
+  return Status::OK();
 }
 
 Status KuduColumnStorageAttributes::StringToCompressionType(
     const string& compression,
     KuduColumnStorageAttributes::CompressionType* type) {
-  Status s;
   string compression_uc;
   ToUpperCase(compression, &compression_uc);
   if (compression_uc == "DEFAULT_COMPRESSION") {
@@ -269,10 +267,10 @@
   } else if (compression_uc == "ZLIB") {
     *type = KuduColumnStorageAttributes::ZLIB;
   } else {
-    s = Status::InvalidArgument(Substitute(
+    return Status::InvalidArgument(Substitute(
         "compression type $0 is not supported", compression));
   }
-  return s;
+  return Status::OK();
 }
 
 ////////////////////////////////////////////////////////////
@@ -711,7 +709,6 @@
 
  Status KuduColumnSchema::StringToDataType(
       const string& type_str, KuduColumnSchema::DataType* type) {
-  Status s;
   string type_uc;
   ToUpperCase(type_str, &type_uc);
   if (type_uc == "INT8") {
@@ -741,10 +738,10 @@
   } else if (type_uc == "DATE") {
     *type = DATE;
   } else {
-    s = Status::InvalidArgument(Substitute(
+    return Status::InvalidArgument(Substitute(
         "data type $0 is not supported", type_str));
   }
-  return s;
+  return Status::OK();
 }
 
 KuduColumnSchema::KuduColumnSchema(const string &name,
@@ -843,8 +840,11 @@
   KuduColumnStorageAttributes::StringToCompressionType(
       kudu::CompressionType_Name(storage_attributes.compression),
       &compression_type);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   return KuduColumnStorageAttributes(encoding_type, compression_type,
                                      storage_attributes.cfile_block_size);
+#pragma GCC diagnostic pop
 }
 
 const string& KuduColumnSchema::comment() const {
diff --git a/src/kudu/gutil/stl_util.h b/src/kudu/gutil/stl_util.h
index ae9df29..2eeb628 100644
--- a/src/kudu/gutil/stl_util.h
+++ b/src/kudu/gutil/stl_util.h
@@ -25,13 +25,12 @@
 // and Google friendly API.
 //
 
-#ifndef UTIL_GTL_STL_UTIL_H_
-#define UTIL_GTL_STL_UTIL_H_
+#pragma once
 
-#include <stddef.h>
-#include <string.h>  // for memcpy
 #include <algorithm>
 #include <cassert>
+#include <cstddef>
+#include <cstring>  // for memcpy
 #include <deque>
 #include <functional>
 #include <iterator>
@@ -309,7 +308,7 @@
 # ifdef NDEBUG
   return &*v->begin();
 # else
-  return v->empty() ? NULL : &*v->begin();
+  return v->empty() ? nullptr : &*v->begin();
 # endif
 }
 
@@ -318,7 +317,7 @@
 # ifdef NDEBUG
   return &*v->begin();
 # else
-  return v->empty() ? NULL : &*v->begin();
+  return v->empty() ? nullptr : &*v->begin();
 # endif
 }
 
@@ -336,7 +335,7 @@
 // implementations.
 inline char* string_as_array(std::string* str) {
   // DO NOT USE const_cast<char*>(str->data())! See the unittest for why.
-  return str->empty() ? NULL : &*str->begin();
+  return str->empty() ? nullptr : &*str->begin();
 }
 
 // These are methods that test two hash maps/sets for equality.  These exist
@@ -379,7 +378,7 @@
 // hash_set, or any other STL container which defines sensible begin(), end(),
 // and clear() methods.
 //
-// If container is NULL, this function is a no-op.
+// If container is nullptr, this function is a no-op.
 //
 // As an alternative to calling STLDeleteElements() directly, consider
 // ElementDeleter (defined below), which ensures that your container's elements
@@ -393,7 +392,7 @@
 
 // Given an STL container consisting of (key, value) pairs, STLDeleteValues
 // deletes all the "value" components and clears the container.  Does nothing
-// in the case it's given a NULL pointer.
+// in the case it's given a null pointer.
 template <class T>
 void STLDeleteValues(T *v) {
   if (!v) return;
@@ -829,8 +828,8 @@
   typedef typename Alloc::pointer pointer;
   typedef typename Alloc::size_type size_type;
 
-  STLCountingAllocator() : bytes_used_(NULL) { }
-  STLCountingAllocator(int64* b) : bytes_used_(b) {}  // TODO(user): explicit?
+  STLCountingAllocator() : bytes_used_(nullptr) { }
+  explicit STLCountingAllocator(int64* b) : bytes_used_(b) {}
 
   // Constructor used for rebinding
   template <class U>
@@ -839,15 +838,18 @@
         bytes_used_(x.bytes_used()) {
   }
 
-  pointer allocate(size_type n, std::allocator<void>::const_pointer hint = 0) {
-    assert(bytes_used_ != NULL);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+  pointer allocate(size_type n, std::allocator<void>::const_pointer hint = nullptr) {
+    assert(bytes_used_ != nullptr);
     *bytes_used_ += n * sizeof(T);
     return Alloc::allocate(n, hint);
   }
+#pragma GCC diagnostic pop
 
   void deallocate(pointer p, size_type n) {
     Alloc::deallocate(p, n);
-    assert(bytes_used_ != NULL);
+    assert(bytes_used_ != nullptr);
     *bytes_used_ -= n * sizeof(T);
   }
 
@@ -933,5 +935,3 @@
   }
   return false;
 }
-
-#endif  // UTIL_GTL_STL_UTIL_H_
diff --git a/src/kudu/security/gssapi.cc b/src/kudu/security/gssapi.cc
index 6797ec3..116b8f9 100644
--- a/src/kudu/security/gssapi.cc
+++ b/src/kudu/security/gssapi.cc
@@ -29,6 +29,13 @@
 
 using std::string;
 
+#if defined(__APPLE__)
+// Almost all functions in the krb5 API are marked as deprecated in favor
+// of GSS.framework in macOS.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif // #if defined(__APPLE__)
+
 namespace kudu {
 namespace gssapi {
 
@@ -162,3 +169,7 @@
 
 } // namespace gssapi
 } // namespace kudu
+
+#if defined(__APPLE__)
+#pragma GCC diagnostic pop
+#endif // #if defined(__APPLE__)
diff --git a/src/kudu/util/mem_tracker.h b/src/kudu/util/mem_tracker.h
index fc83363..fca7540 100644
--- a/src/kudu/util/mem_tracker.h
+++ b/src/kudu/util/mem_tracker.h
@@ -14,8 +14,7 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-#ifndef KUDU_UTIL_MEM_TRACKER_H
-#define KUDU_UTIL_MEM_TRACKER_H
+#pragma once
 
 #include <cstdint>
 #include <list>
@@ -223,6 +222,8 @@
   ~MemTrackerAllocator() {
   }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
   pointer allocate(size_type n, const_pointer hint = 0) {
     // Ideally we'd use TryConsume() here to enforce the tracker's limit.
     // However, that means throwing bad_alloc if the limit is exceeded, and
@@ -241,6 +242,7 @@
   struct rebind {
     typedef MemTrackerAllocator<U, typename Alloc::template rebind<U>::other> other;
   };
+#pragma GCC diagnostic pop
 
   const std::shared_ptr<MemTracker>& mem_tracker() const { return mem_tracker_; }
 
@@ -277,5 +279,3 @@
 };
 
 } // namespace kudu
-
-#endif // KUDU_UTIL_MEM_TRACKER_H
diff --git a/src/kudu/util/memory/arena.h b/src/kudu/util/memory/arena.h
index 6eaa477..aec712e 100644
--- a/src/kudu/util/memory/arena.h
+++ b/src/kudu/util/memory/arena.h
@@ -251,9 +251,12 @@
 
   ~ArenaAllocator() { }
 
-  pointer allocate(size_type n, std::allocator<void>::const_pointer /*hint*/ = 0) {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+  pointer allocate(size_type n, std::allocator<void>::const_pointer /*hint*/ = nullptr) {
     return reinterpret_cast<T*>(arena_->AllocateBytes(n * sizeof(T)));
   }
+#pragma GCC diagnostic pop
 
   void deallocate(pointer p, size_type n) {}