From f2542f22fe3890a3207157247a7c1d93efd0022f Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 18 May 2025 12:34:53 +0900 Subject: [PATCH] Require C++14 (#2596) This only has some minor additions of std::make_unique, digits separators, std::string literals, and more flexible constexpr. References #2469. --- .clang-tidy | 1 - .github/workflows/ci.yml | 2 +- Makefile.am | 2 +- configure.ac | 2 +- src/Makefile.am | 2 +- src/cache.cpp | 4 +-- src/curl_share.cpp | 2 +- src/curl_util.cpp | 4 ++- src/fdcache_entity.cpp | 10 +++---- src/fdcache_page.cpp | 4 +-- src/gnutls_auth.cpp | 8 +++--- src/nss_auth.cpp | 2 +- src/openssl_auth.cpp | 5 ++-- src/s3fs.cpp | 8 +++--- src/s3fs_cred.cpp | 6 +++-- src/s3fs_logger.cpp | 4 +-- src/s3fs_util.cpp | 10 +++---- src/s3fs_util.h | 2 +- src/sighandlers.cpp | 7 ++--- src/sighandlers.h | 3 +-- src/string_util.cpp | 20 +++++++------- src/test_string_util.cpp | 56 +++++++++++++++++++++------------------- src/threadpoolman.cpp | 2 +- src/threadpoolman.h | 3 +-- src/types.h | 2 +- test/Makefile.am | 2 +- test/write_multiblock.cc | 2 +- 27 files changed, 89 insertions(+), 86 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index fbc57e6..15e4458 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -54,7 +54,6 @@ Checks: ' -misc-use-internal-linkage, -modernize-avoid-c-arrays, -modernize-loop-convert, - -modernize-make-unique, -modernize-use-nodiscard, -modernize-raw-string-literal, -modernize-return-braced-init-list, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b963af..1151be7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,7 +146,7 @@ jobs: - name: Build run: | ./autogen.sh - PKG_CONFIG_PATH=/usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/openssl/lib/pkgconfig ./configure CXXFLAGS='-std=c++11 -DS3FS_PTHREAD_ERRORCHECK=1' + PKG_CONFIG_PATH=/usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/openssl/lib/pkgconfig ./configure CXXFLAGS='-std=c++14 -DS3FS_PTHREAD_ERRORCHECK=1' make --jobs=$(sysctl -n hw.ncpu) - name: Cppcheck diff --git a/Makefile.am b/Makefile.am index 21e44f4..9143f88 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,7 +38,7 @@ clang-tidy: cppcheck: cppcheck --quiet --error-exitcode=1 \ --inline-suppr \ - --std=c++11 \ + --std=c++14 \ --xml \ -D HAVE_ATTR_XATTR_H \ -D HAVE_SYS_EXTATTR_H \ diff --git a/configure.ac b/configure.ac index 68637fb..d18d58c 100644 --- a/configure.ac +++ b/configure.ac @@ -34,7 +34,7 @@ AC_CHECK_HEADERS([attr/xattr.h]) AC_CHECK_HEADERS([sys/extattr.h]) AC_CHECK_FUNCS([fallocate]) -CXXFLAGS="-Wall -fno-exceptions -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=3 -std=c++11 $CXXFLAGS" +CXXFLAGS="-Wall -fno-exceptions -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=3 -std=c++14 $CXXFLAGS" dnl ---------------------------------------------- dnl For macOS diff --git a/src/Makefile.am b/src/Makefile.am index 94d838a..c4ea4a8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -102,7 +102,7 @@ TESTS = \ test_string_util clang-tidy: - clang-tidy -extra-arg-before=-xc++ \ + clang-tidy -extra-arg-before=-xc++ -extra-arg=-std=c++14 \ *.h $(s3fs_SOURCES) test_curl_util.cpp test_page_list.cpp test_string_util.cpp \ -- $(DEPS_CFLAGS) $(CPPFLAGS) diff --git a/src/cache.cpp b/src/cache.cpp index e4a140b..2d38426 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -44,7 +44,7 @@ static void SetStatCacheTime(struct timespec& ts) } } -static int CompareStatCacheTime(const struct timespec& ts1, const struct timespec& ts2) +static constexpr int CompareStatCacheTime(const struct timespec& ts1, const struct timespec& ts2) { // return -1: ts1 < ts2 // 0: ts1 == ts2 @@ -119,7 +119,7 @@ std::mutex StatCache::stat_cache_lock; //------------------------------------------------------------------- // Constructor/Destructor //------------------------------------------------------------------- -StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100000), IsCacheNoObject(true) +StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100'000), IsCacheNoObject(true) { if(this == StatCache::getStatCacheData()){ stat_cache.clear(); diff --git a/src/curl_share.cpp b/src/curl_share.cpp index add7c66..5d0c656 100644 --- a/src/curl_share.cpp +++ b/src/curl_share.cpp @@ -203,7 +203,7 @@ CURLSH* S3fsCurlShare::GetCurlShareHandle() S3FS_PRN_ERR("Failed to create curl share handle"); return nullptr; } - ShareLocksPtr pLocks(new curl_share_locks); + auto pLocks = std::make_unique(); // Initialize curl share handle if(!S3fsCurlShare::InitializeCurlShare(hShare, pLocks)){ diff --git a/src/curl_util.cpp b/src/curl_util.cpp index f0cb874..e3b1476 100644 --- a/src/curl_util.cpp +++ b/src/curl_util.cpp @@ -30,6 +30,8 @@ #include "s3fs_auth.h" #include "s3fs_cred.h" +using namespace std::string_literals; + //------------------------------------------------------------------- // Utility Functions //------------------------------------------------------------------- @@ -47,7 +49,7 @@ struct curl_slist* curl_slist_sort_insert(struct curl_slist* list, const char* k // key & value are trimmed and lower (only key) std::string strkey = trim(key); std::string strval = value ? trim(value) : ""; - std::string strnew = key + std::string(": ") + strval; + std::string strnew = key + ": "s + strval; char* data; if(nullptr == (data = strdup(strnew.c_str()))){ return list; diff --git a/src/fdcache_entity.cpp b/src/fdcache_entity.cpp index 370f1ec..ac478f9 100644 --- a/src/fdcache_entity.cpp +++ b/src/fdcache_entity.cpp @@ -49,7 +49,7 @@ //------------------------------------------------ // Symbols //------------------------------------------------ -static constexpr int MAX_MULTIPART_CNT = 10 * 1000; // S3 multipart max count +static constexpr int MAX_MULTIPART_CNT = 10'000; // S3 multipart max count //------------------------------------------------ // FdEntity class variables @@ -247,7 +247,7 @@ int FdEntity::DupWithLock(int fd) return -1; } const PseudoFdInfo* org_pseudoinfo = iter->second.get(); - std::unique_ptr ppseudoinfo(new PseudoFdInfo(physical_fd, (org_pseudoinfo ? org_pseudoinfo->GetFlags() : 0))); + auto ppseudoinfo = std::make_unique(physical_fd, (org_pseudoinfo ? org_pseudoinfo->GetFlags() : 0)); int pseudo_fd = ppseudoinfo->GetPseudoFd(); pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo); @@ -263,7 +263,7 @@ int FdEntity::OpenPseudoFd(int flags) if(-1 == physical_fd){ return -1; } - std::unique_ptr ppseudoinfo(new PseudoFdInfo(physical_fd, flags)); + auto ppseudoinfo = std::make_unique(physical_fd, flags); int pseudo_fd = ppseudoinfo->GetPseudoFd(); pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo); @@ -456,7 +456,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts } // open cache and cache stat file, load page info. - pcfstat.reset(new CacheFileStat(path.c_str())); + pcfstat = std::make_unique(path.c_str()); // try to open cache file if( -1 != (physical_fd = open(cachepath.c_str(), O_RDWR)) && @@ -628,7 +628,7 @@ int FdEntity::Open(const headers_t* pmeta, off_t size, const struct timespec& ts } // create new pseudo fd, and set it to map - std::unique_ptr ppseudoinfo(new PseudoFdInfo(physical_fd, flags)); + auto ppseudoinfo = std::make_unique(physical_fd, flags); int pseudo_fd = ppseudoinfo->GetPseudoFd(); pseudo_fd_map[pseudo_fd] = std::move(ppseudoinfo); diff --git a/src/fdcache_page.cpp b/src/fdcache_page.cpp index 7daa52a..b47e8a3 100644 --- a/src/fdcache_page.cpp +++ b/src/fdcache_page.cpp @@ -234,7 +234,7 @@ bool PageList::GetSparseFilePages(int fd, size_t file_size, fdpage_list_t& spars // bool PageList::CheckZeroAreaInFile(int fd, off_t start, size_t bytes) { - std::unique_ptr readbuff(new char[CHECK_CACHEFILE_PART_SIZE]); + auto readbuff = std::make_unique(CHECK_CACHEFILE_PART_SIZE); for(size_t comp_bytes = 0, check_bytes = 0; comp_bytes < bytes; comp_bytes += check_bytes){ if(CHECK_CACHEFILE_PART_SIZE < (bytes - comp_bytes)){ @@ -868,7 +868,7 @@ bool PageList::Deserialize(CacheFileStat& file, ino_t inode) Init(0, false, false); return true; } - std::unique_ptr ptmp(new char[st.st_size + 1]); + auto ptmp = std::make_unique(st.st_size + 1); ssize_t result; // read from file if(0 >= (result = pread(file.GetFd(), ptmp.get(), st.st_size, 0))){ diff --git a/src/gnutls_auth.cpp b/src/gnutls_auth.cpp index 947d5c8..9467843 100644 --- a/src/gnutls_auth.cpp +++ b/src/gnutls_auth.cpp @@ -111,7 +111,7 @@ std::unique_ptr s3fs_HMAC(const void* key, size_t keylen, const return nullptr; } - std::unique_ptr digest(new unsigned char[SHA1_DIGEST_SIZE]); + auto digest = std::make_unique(SHA1_DIGEST_SIZE); struct hmac_sha1_ctx ctx_hmac; hmac_sha1_set_key(&ctx_hmac, keylen, reinterpret_cast(key)); @@ -128,7 +128,7 @@ std::unique_ptr s3fs_HMAC256(const void* key, size_t keylen, co return nullptr; } - std::unique_ptr digest(new unsigned char[SHA256_DIGEST_SIZE]); + auto digest = std::make_unique(SHA256_DIGEST_SIZE); struct hmac_sha256_ctx ctx_hmac; hmac_sha256_set_key(&ctx_hmac, keylen, reinterpret_cast(key)); @@ -150,7 +150,7 @@ std::unique_ptr s3fs_HMAC(const void* key, size_t keylen, const if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA1))){ return nullptr; } - std::unique_ptr digest(new unsigned char[*digestlen + 1]); + auto digest = std::make_unique(*digestlen + 1); if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA1, key, keylen, data, datalen, digest.get())){ return nullptr; } @@ -166,7 +166,7 @@ std::unique_ptr s3fs_HMAC256(const void* key, size_t keylen, co if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA256))){ return nullptr; } - std::unique_ptr digest(new unsigned char[*digestlen + 1]); + auto digest = std::make_unique(*digestlen + 1); if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA256, key, keylen, data, datalen, digest.get())){ return nullptr; } diff --git a/src/nss_auth.cpp b/src/nss_auth.cpp index 486f269..cc0cf62 100644 --- a/src/nss_auth.cpp +++ b/src/nss_auth.cpp @@ -126,7 +126,7 @@ static std::unique_ptr s3fs_HMAC_RAW(const void* key, size_t ke PK11_FreeSymKey(pKey); PK11_FreeSlot(Slot); - std::unique_ptr digest(new unsigned char[*digestlen]); + auto digest = std::make_unique(*digestlen); memcpy(digest.get(), tmpdigest, *digestlen); return digest; diff --git a/src/openssl_auth.cpp b/src/openssl_auth.cpp index e42e2a5..837d5cd 100644 --- a/src/openssl_auth.cpp +++ b/src/openssl_auth.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -138,7 +139,7 @@ bool s3fs_init_crypt_mutex() return false; } } - s3fs_crypt_mutex.reset(new std::mutex[CRYPTO_num_locks()]); + s3fs_crypt_mutex = std::make_unique(CRYPTO_num_locks()); // static lock CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock); CRYPTO_set_id_callback(s3fs_crypt_get_threadid); @@ -177,7 +178,7 @@ static std::unique_ptr s3fs_HMAC_RAW(const void* key, size_t ke return nullptr; } (*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char); - std::unique_ptr digest(new unsigned char[*digestlen]); + auto digest = std::make_unique(*digestlen); if(is_sha256){ HMAC(EVP_sha256(), key, static_cast(keylen), data, datalen, digest.get(), digestlen); }else{ diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 9cd4d7a..5f1fa44 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -204,17 +204,17 @@ static std::atomic has_mp_stat; //------------------------------------------------------------------- // Functions //------------------------------------------------------------------- -static bool IS_REPLACEDIR(dirtype type) +static constexpr bool IS_REPLACEDIR(dirtype type) { return dirtype::OLD == type || dirtype::FOLDER == type || dirtype::NOOBJ == type; } -static bool IS_RMTYPEDIR(dirtype type) +static constexpr bool IS_RMTYPEDIR(dirtype type) { return dirtype::OLD == type || dirtype::FOLDER == type; } -static bool IS_CREATE_MP_STAT(const char* path) +static constexpr bool IS_CREATE_MP_STAT(const char* path) { // [NOTE] has_mp_stat is set in get_object_attribute() return (path != nullptr && 0 == strcmp(path, "/") && !has_mp_stat); @@ -5386,7 +5386,7 @@ int main(int argc, char* argv[]) // set credential object // - ps3fscred.reset(new S3fsCred()); + ps3fscred = std::make_unique(); if(!S3fsCurl::InitCredentialObject(ps3fscred.get())){ S3FS_PRN_EXIT("Failed to setup credential object to s3fs curl."); exit(EXIT_FAILURE); diff --git a/src/s3fs_cred.cpp b/src/s3fs_cred.cpp index d421f29..284ca37 100644 --- a/src/s3fs_cred.cpp +++ b/src/s3fs_cred.cpp @@ -38,6 +38,8 @@ #include "threadpoolman.h" #include "s3fs_threadreqs.h" +using namespace std::string_literals; + //------------------------------------------------------------------- // Symbols //------------------------------------------------------------------- @@ -1012,7 +1014,7 @@ bool S3fsCred::InitialS3fsCredentials() } // 3b - check ${HOME}/.aws/credentials - std::string aws_credentials = std::string(getpwuid(getuid())->pw_dir) + "/.aws/credentials"; + std::string aws_credentials = getpwuid(getuid())->pw_dir + "/.aws/credentials"s; if(ReadAwsCredentialFile(aws_credentials)){ return true; }else if(aws_profile != DEFAULT_AWS_PROFILE_NAME){ @@ -1409,7 +1411,7 @@ int S3fsCred::DetectParam(const char* arg) S3FS_PRN_EXIT("option ibm_iam_endpoint has invalid format, missing http / https protocol"); return -1; } - endpoint_url = std::string(iam_endpoint) + "/identity/token"; + endpoint_url = iam_endpoint + "/identity/token"s; SetIAMCredentialsURL(endpoint_url.c_str()); set_builtin_cred_opts = true; return 0; diff --git a/src/s3fs_logger.cpp b/src/s3fs_logger.cpp index 7a6b411..ee78765 100644 --- a/src/s3fs_logger.cpp +++ b/src/s3fs_logger.cpp @@ -258,7 +258,7 @@ void s3fs_low_logprn(S3fsLog::s3fs_log_level level, const char* file, const char size_t len = vsnprintf(nullptr, 0, fmt, va) + 1; va_end(va); - std::unique_ptr message(new char[len]); + auto message = std::make_unique(len); va_start(va, fmt); vsnprintf(message.get(), len, fmt, va); va_end(va); @@ -282,7 +282,7 @@ void s3fs_low_logprn2(S3fsLog::s3fs_log_level level, int nest, const char* file, size_t len = vsnprintf(nullptr, 0, fmt, va) + 1; va_end(va); - std::unique_ptr message(new char[len]); + auto message = std::make_unique(len); va_start(va, fmt); vsnprintf(message.get(), len, fmt, va); va_end(va); diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index f2c717f..5e16549 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -101,11 +101,11 @@ std::string get_username(uid_t uid) struct passwd* ppwinfo = nullptr; // make buffer - std::unique_ptr pbuf(new char[maxlen]); + auto pbuf = std::make_unique(maxlen); // get pw information while(ERANGE == (result = getpwuid_r(uid, &pwinfo, pbuf.get(), maxlen, &ppwinfo))){ maxlen *= 2; - pbuf.reset(new char[maxlen]); + pbuf = std::make_unique(maxlen); } if(0 != result){ @@ -129,11 +129,11 @@ int is_uid_include_group(uid_t uid, gid_t gid) struct group* pginfo = nullptr; // make buffer - std::unique_ptr pbuf(new char[maxlen]); + auto pbuf = std::make_unique(maxlen); // get group information while(ERANGE == (result = getgrgid_r(gid, &ginfo, pbuf.get(), maxlen, &pginfo))){ maxlen *= 2; - pbuf.reset(new char[maxlen]); + pbuf = std::make_unique(maxlen); } if(0 != result){ @@ -410,7 +410,7 @@ void print_launch_message(int argc, char** argv) // 0 ts1 == ts2 // 1 ts1 > ts2 // -int compare_timespec(const struct timespec& ts1, const struct timespec& ts2) +constexpr int compare_timespec(const struct timespec& ts1, const struct timespec& ts2) { if(ts1.tv_sec < ts2.tv_sec){ return -1; diff --git a/src/s3fs_util.h b/src/s3fs_util.h index 2bd2a24..8667b3b 100644 --- a/src/s3fs_util.h +++ b/src/s3fs_util.h @@ -73,7 +73,7 @@ enum class stat_time_type : uint8_t { //------------------------------------------------------------------- static constexpr struct timespec S3FS_OMIT_TS = {0, UTIME_OMIT}; -int compare_timespec(const struct timespec& ts1, const struct timespec& ts2); +constexpr int compare_timespec(const struct timespec& ts1, const struct timespec& ts2); int compare_timespec(const struct stat& st, stat_time_type type, const struct timespec& ts); void set_timespec_to_stat(struct stat& st, stat_time_type type, const struct timespec& ts); struct timespec* set_stat_to_timespec(const struct stat& st, stat_time_type type, struct timespec& ts); diff --git a/src/sighandlers.cpp b/src/sighandlers.cpp index 0a0a37a..a38b9ab 100644 --- a/src/sighandlers.cpp +++ b/src/sighandlers.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -40,7 +41,7 @@ bool S3fsSignals::enableUsr1 = false; bool S3fsSignals::Initialize() { if(!S3fsSignals::pSingleton){ - S3fsSignals::pSingleton.reset(new S3fsSignals); + S3fsSignals::pSingleton = std::make_unique(); } return true; } @@ -193,8 +194,8 @@ bool S3fsSignals::InitUsr1Handler() } // create thread - std::unique_ptr pSemUsr1_tmp(new Semaphore(0)); - pThreadUsr1.reset(new std::thread(S3fsSignals::CheckCacheWorker, pSemUsr1_tmp.get())); + auto pSemUsr1_tmp = std::make_unique(0); + pThreadUsr1 = std::make_unique(S3fsSignals::CheckCacheWorker, pSemUsr1_tmp.get()); pSemUsr1 = std::move(pSemUsr1_tmp); // set handler diff --git a/src/sighandlers.h b/src/sighandlers.h index 5227dee..2dc7a70 100644 --- a/src/sighandlers.h +++ b/src/sighandlers.h @@ -50,13 +50,12 @@ class S3fsSignals static void HandlerHUP(int sig); static bool InitHupHandler(); - S3fsSignals(); - bool InitUsr1Handler(); bool DestroyUsr1Handler(); bool WakeupUsr1Thread(); public: + S3fsSignals(); ~S3fsSignals(); S3fsSignals(const S3fsSignals&) = delete; S3fsSignals(S3fsSignals&&) = delete; diff --git a/src/string_util.cpp b/src/string_util.cpp index 4a13eea..78051c6 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -404,25 +404,23 @@ std::string s3fs_base64(const unsigned char* input, size_t length) return result; } -static inline unsigned char char_decode64(const char ch) +static constexpr unsigned char char_decode64(const char ch) { - unsigned char by; if('A' <= ch && ch <= 'Z'){ // A - Z - by = static_cast(ch - 'A'); + return static_cast(ch - 'A'); }else if('a' <= ch && ch <= 'z'){ // a - z - by = static_cast(ch - 'a' + 26); + return static_cast(ch - 'a' + 26); }else if('0' <= ch && ch <= '9'){ // 0 - 9 - by = static_cast(ch - '0' + 52); + return static_cast(ch - '0' + 52); }else if('+' == ch){ // + - by = 62; + return 62; }else if('/' == ch){ // / - by = 63; + return 63; }else if('=' == ch){ // = - by = 64; + return 64; }else{ // something wrong - by = UCHAR_MAX; + return UCHAR_MAX; } - return by; } std::string s3fs_decode64(const char* input, size_t input_len) @@ -509,7 +507,7 @@ bool s3fs_wtf8_encode(const char *s, std::string *result) // four byte encoding if ((c & 0xf8) == 0xf0 && (s[1] & 0xc0) == 0x80 && (s[2] & 0xc0) == 0x80 && (s[3] & 0xc0) == 0x80) { const unsigned code = ((c & 0x07) << 18) | ((s[1] & 0x3f) << 12) | ((s[2] & 0x3f) << 6) | (s[3] & 0x3f); - if (code >= 0x10000 && code <= 0x10ffff) { + if (code >= 0x10'000 && code <= 0x10f'fff) { // not overlong and in defined unicode space if (result) { *result += c; diff --git a/src/test_string_util.cpp b/src/test_string_util.cpp index 00e6165..0fbd675 100644 --- a/src/test_string_util.cpp +++ b/src/test_string_util.cpp @@ -27,6 +27,8 @@ #include "string_util.h" #include "test_util.h" +using namespace std::string_literals; + //------------------------------------------------------------------- // Global variables for test_string_util //------------------------------------------------------------------- @@ -35,29 +37,29 @@ std::string instance_name; void test_trim() { - ASSERT_EQUALS(std::string("1234"), trim(" 1234 ")); - ASSERT_EQUALS(std::string("1234"), trim("1234 ")); - ASSERT_EQUALS(std::string("1234"), trim(" 1234")); - ASSERT_EQUALS(std::string("1234"), trim("1234")); + ASSERT_EQUALS("1234"s, trim(" 1234 ")); + ASSERT_EQUALS("1234"s, trim("1234 ")); + ASSERT_EQUALS("1234"s, trim(" 1234")); + ASSERT_EQUALS("1234"s, trim("1234")); - ASSERT_EQUALS(std::string("1234 "), trim_left(" 1234 ")); - ASSERT_EQUALS(std::string("1234 "), trim_left("1234 ")); - ASSERT_EQUALS(std::string("1234"), trim_left(" 1234")); - ASSERT_EQUALS(std::string("1234"), trim_left("1234")); + ASSERT_EQUALS("1234 "s, trim_left(" 1234 ")); + ASSERT_EQUALS("1234 "s, trim_left("1234 ")); + ASSERT_EQUALS("1234"s, trim_left(" 1234")); + ASSERT_EQUALS("1234"s, trim_left("1234")); - ASSERT_EQUALS(std::string(" 1234"), trim_right(" 1234 ")); - ASSERT_EQUALS(std::string("1234"), trim_right("1234 ")); - ASSERT_EQUALS(std::string(" 1234"), trim_right(" 1234")); - ASSERT_EQUALS(std::string("1234"), trim_right("1234")); + ASSERT_EQUALS(" 1234"s, trim_right(" 1234 ")); + ASSERT_EQUALS("1234"s, trim_right("1234 ")); + ASSERT_EQUALS(" 1234"s, trim_right(" 1234")); + ASSERT_EQUALS("1234"s, trim_right("1234")); - ASSERT_EQUALS(std::string("1234"), peeloff("\"1234\"")); // "1234" -> 1234 - ASSERT_EQUALS(std::string("\"1234\""), peeloff("\"\"1234\"\"")); // ""1234"" -> "1234" - ASSERT_EQUALS(std::string("\"1234"), peeloff("\"\"1234\"")); // ""1234" -> "1234 - ASSERT_EQUALS(std::string("1234\""), peeloff("\"1234\"\"")); // "1234"" -> 1234" - ASSERT_EQUALS(std::string("\"1234"), peeloff("\"1234")); // "1234 -> "1234 - ASSERT_EQUALS(std::string("1234\""), peeloff("1234\"")); // 1234" -> 1234" - ASSERT_EQUALS(std::string(" \"1234\""), peeloff(" \"1234\"")); // _"1234" -> _"1234" - ASSERT_EQUALS(std::string("\"1234\" "), peeloff("\"1234\" ")); // "1234"_ -> "1234"_ + ASSERT_EQUALS("1234"s, peeloff("\"1234\"")); // "1234" -> 1234 + ASSERT_EQUALS("\"1234\""s, peeloff("\"\"1234\"\"")); // ""1234"" -> "1234" + ASSERT_EQUALS("\"1234"s, peeloff("\"\"1234\"")); // ""1234" -> "1234 + ASSERT_EQUALS("1234\""s, peeloff("\"1234\"\"")); // "1234"" -> 1234" + ASSERT_EQUALS("\"1234"s, peeloff("\"1234")); // "1234 -> "1234 + ASSERT_EQUALS("1234\""s, peeloff("1234\"")); // 1234" -> 1234" + ASSERT_EQUALS(" \"1234\""s, peeloff(" \"1234\"")); // _"1234" -> _"1234" + ASSERT_EQUALS("\"1234\" "s, peeloff("\"1234\" ")); // "1234"_ -> "1234"_ } void test_base64() @@ -65,30 +67,30 @@ void test_base64() std::string buf; char tmpbuf = '\0'; - ASSERT_EQUALS(s3fs_base64(nullptr, 0), std::string("")); + ASSERT_EQUALS(s3fs_base64(nullptr, 0), ""s); buf = s3fs_decode64(nullptr, 0); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), &tmpbuf, 0); - ASSERT_EQUALS(s3fs_base64(reinterpret_cast(""), 0), std::string("")); + ASSERT_EQUALS(s3fs_base64(reinterpret_cast(""), 0), ""s); buf = s3fs_decode64("", 0); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), &tmpbuf, 0); - ASSERT_EQUALS(s3fs_base64(reinterpret_cast("1"), 1), std::string("MQ==")); + ASSERT_EQUALS(s3fs_base64(reinterpret_cast("1"), 1), "MQ=="s); buf = s3fs_decode64("MQ==", 4); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "1", 1); ASSERT_EQUALS(buf.length(), static_cast(1)); - ASSERT_EQUALS(s3fs_base64(reinterpret_cast("12"), 2), std::string("MTI=")); + ASSERT_EQUALS(s3fs_base64(reinterpret_cast("12"), 2), "MTI="s); buf = s3fs_decode64("MTI=", 4); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "12", 2); ASSERT_EQUALS(buf.length(), static_cast(2)); - ASSERT_EQUALS(s3fs_base64(reinterpret_cast("123"), 3), std::string("MTIz")); + ASSERT_EQUALS(s3fs_base64(reinterpret_cast("123"), 3), "MTIz"s); buf = s3fs_decode64("MTIz", 4); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "123", 3); ASSERT_EQUALS(buf.length(), static_cast(3)); - ASSERT_EQUALS(s3fs_base64(reinterpret_cast("1234"), 4), std::string("MTIzNA==")); + ASSERT_EQUALS(s3fs_base64(reinterpret_cast("1234"), 4), "MTIzNA=="s); buf = s3fs_decode64("MTIzNA==", 8); ASSERT_BUFEQUALS(buf.c_str(), buf.length(), "1234", 4); ASSERT_EQUALS(buf.length(), static_cast(4)); @@ -121,7 +123,7 @@ void test_strtoofft() ASSERT_EQUALS(value, static_cast(15L)); ASSERT_TRUE(s3fs_strtoofft(&value, "deadbeef", /*base=*/ 16)); - ASSERT_EQUALS(value, static_cast(3735928559L)); + ASSERT_EQUALS(value, static_cast(3'735'928'559L)); } void test_wtf8_encoding() diff --git a/src/threadpoolman.cpp b/src/threadpoolman.cpp index 653bf05..95839bd 100644 --- a/src/threadpoolman.cpp +++ b/src/threadpoolman.cpp @@ -49,7 +49,7 @@ bool ThreadPoolMan::Initialize(int count) if(-1 != count){ ThreadPoolMan::SetWorkerCount(count); } - ThreadPoolMan::singleton.reset(new ThreadPoolMan(ThreadPoolMan::worker_count)); + ThreadPoolMan::singleton = std::make_unique(ThreadPoolMan::worker_count); return true; } diff --git a/src/threadpoolman.h b/src/threadpoolman.h index 228f4cb..fb6bf75 100644 --- a/src/threadpoolman.h +++ b/src/threadpoolman.h @@ -76,8 +76,6 @@ class ThreadPoolMan private: static void Worker(ThreadPoolMan* psingleton, std::promise promise); - explicit ThreadPoolMan(int count = 1); - bool IsExit() const; void SetExitFlag(bool exit_flag); @@ -86,6 +84,7 @@ class ThreadPoolMan void SetInstruction(const thpoolman_param& pparam); public: + explicit ThreadPoolMan(int count = 1); ~ThreadPoolMan(); ThreadPoolMan(const ThreadPoolMan&) = delete; ThreadPoolMan(ThreadPoolMan&&) = delete; diff --git a/src/types.h b/src/types.h index a9b0013..c4344d8 100644 --- a/src/types.h +++ b/src/types.h @@ -67,7 +67,7 @@ enum class acl_t : uint8_t { UNKNOWN }; -inline const char* str(acl_t value) +constexpr const char* str(acl_t value) { switch(value){ case acl_t::PRIVATE: diff --git a/test/Makefile.am b/test/Makefile.am index 5bb7210..db6f311 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -43,7 +43,7 @@ truncate_read_file_SOURCES = truncate_read_file.cc cr_filename_SOURCES = cr_filename.cc clang-tidy: - clang-tidy \ + clang-tidy -extra-arg=-std=c++14 \ $(junk_data_SOURCES) \ $(write_multiblock_SOURCES) \ $(mknod_test_SOURCES) \ diff --git a/test/write_multiblock.cc b/test/write_multiblock.cc index 0bd0788..a701c31 100644 --- a/test/write_multiblock.cc +++ b/test/write_multiblock.cc @@ -62,7 +62,7 @@ static std::unique_ptr create_random_data(off_t size) return nullptr; } - std::unique_ptr pbuff(new unsigned char[size]); + auto pbuff = std::make_unique(size); for(ssize_t readpos = 0, readcnt = 0; readpos < size; readpos += readcnt){ if(-1 == (readcnt = read(fd, &(pbuff[readpos]), static_cast(size - readpos)))){ if(EAGAIN != errno && EWOULDBLOCK != errno && EINTR != errno){