Swift: Fix some C++20 todos.

This commit is contained in:
Alexandre Boulgakov
2023-06-08 13:11:14 +01:00
parent 5952a729df
commit 838130ca3a
2 changed files with 4 additions and 5 deletions

View File

@@ -1,11 +1,11 @@
#pragma once
#include <bit>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include "absl/numeric/bits.h"
#include <binlog/binlog.hpp>
#include <cmath>
#include <charconv>
@@ -52,7 +52,7 @@ class UntypedTrapLabel {
size_t strSize() const {
if (id_ == 0) return 2; // #0
// Number of hex digits is ceil(bit_width(id) / 4), but C++ integer division can only do floor.
return /* # */ 1 + /* hex digits */ 1 + (absl::bit_width(id_) - 1) / 4;
return /* # */ 1 + /* hex digits */ 1 + (std::bit_width(id_) - 1) / 4;
}
friend bool operator!=(UntypedTrapLabel lhs, UntypedTrapLabel rhs) { return lhs.id_ != rhs.id_; }

View File

@@ -55,15 +55,14 @@
#define DIAGNOSE_CRITICAL(ID, ...) DIAGNOSE_WITH_LEVEL(critical, ID, __VA_ARGS__)
#define CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX "[{}] "
// TODO(C++20) replace non-standard , ##__VA_ARGS__ with __VA_OPT__(,) __VA_ARGS__
#define DIAGNOSE_WITH_LEVEL(LEVEL, ID, FORMAT, ...) \
do { \
auto _now = ::binlog::clockNow(); \
const ::codeql::SwiftDiagnostic& _id = ID; \
::codeql::Log::diagnose(_id, std::chrono::nanoseconds{_now}, \
fmt::format(FORMAT, ##__VA_ARGS__)); \
fmt::format(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \
LOG_WITH_LEVEL_AND_TIME(LEVEL, _now, CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX FORMAT, \
_id.abbreviation(), ##__VA_ARGS__); \
_id.abbreviation() __VA_OPT__(, ) __VA_ARGS__); \
} while (false)
// avoid calling into binlog's original macros