src: add some noexcept

This commit is contained in:
Markus F.X.J. Oberhumer 2023-10-26 00:28:36 +02:00
parent 2724039c09
commit 29b4752d0e
4 changed files with 70 additions and 34 deletions

View File

@ -308,10 +308,21 @@ def main():
if yaml:
parser.add_argument(
"-export-fixes",
metavar="filename",
metavar="file_or_directory",
dest="export_fixes",
help="Create a yaml file to store suggested fixes in, "
"which can be applied with clang-apply-replacements.",
help="A directory or a yaml file to store suggested fixes in, "
"which can be applied with clang-apply-replacements. If the "
"parameter is a directory, the fixes of each compilation unit are "
"stored in individual yaml files in the directory.",
)
else:
parser.add_argument(
"-export-fixes",
metavar="directory",
dest="export_fixes",
help="A directory to store suggested fixes in, which can be applied "
"with clang-apply-replacements. The fixes of each compilation unit are "
"stored in individual yaml files in the directory.",
)
parser.add_argument(
"-j",
@ -384,14 +395,35 @@ def main():
clang_tidy_binary = find_binary(args.clang_tidy_binary, "clang-tidy", build_path)
tmpdir = None
if args.fix:
clang_apply_replacements_binary = find_binary(
args.clang_apply_replacements_binary, "clang-apply-replacements", build_path
)
if args.fix or (yaml and args.export_fixes):
tmpdir = tempfile.mkdtemp()
combine_fixes = False
export_fixes_dir = None
delete_fixes_dir = False
if args.export_fixes is not None:
# if a directory is given, create it if it does not exist
if args.export_fixes.endswith(os.path.sep) and not os.path.isdir(
args.export_fixes
):
os.makedirs(args.export_fixes)
if not os.path.isdir(args.export_fixes):
if not yaml:
raise RuntimeError(
"Cannot combine fixes in one yaml file. Either install PyYAML or specify an output directory."
)
combine_fixes = True
if os.path.isdir(args.export_fixes):
export_fixes_dir = args.export_fixes
if export_fixes_dir is None and (args.fix or combine_fixes):
export_fixes_dir = tempfile.mkdtemp()
delete_fixes_dir = True
# Load the database and extract all files.
database = json.load(open(os.path.join(build_path, db_path)))
@ -410,8 +442,8 @@ def main():
matched_files.append(name)
files = sorted(matched_files)
if not files:
if tmpdir:
shutil.rmtree(tmpdir)
if delete_fixes_dir:
shutil.rmtree(export_fixes_dir)
sys.exit(0)
try:
@ -462,7 +494,7 @@ def main():
args=(
args,
clang_tidy_binary,
tmpdir,
export_fixes_dir,
build_path,
task_queue,
lock,
@ -486,14 +518,14 @@ def main():
# This is a sad hack. Unfortunately subprocess goes
# bonkers with ctrl-c and we start forking merrily.
print("\nCtrl-C detected, goodbye.")
if tmpdir:
shutil.rmtree(tmpdir)
if delete_fixes_dir:
shutil.rmtree(export_fixes_dir)
os.kill(0, 9)
if yaml and args.export_fixes:
if combine_fixes:
print("Writing fixes to " + args.export_fixes + " ...")
try:
merge_replacement_files(tmpdir, args.export_fixes)
merge_replacement_files(export_fixes_dir, args.export_fixes)
except:
print("Error exporting fixes.\n", file=sys.stderr)
traceback.print_exc()
@ -502,14 +534,14 @@ def main():
if args.fix:
print("Applying fixes ...")
try:
apply_fixes(args, clang_apply_replacements_binary, tmpdir)
apply_fixes(args, clang_apply_replacements_binary, export_fixes_dir)
except:
print("Error applying fixes.\n", file=sys.stderr)
traceback.print_exc()
return_code = 1
if tmpdir:
shutil.rmtree(tmpdir)
if delete_fixes_dir:
shutil.rmtree(export_fixes_dir)
sys.exit(return_code)

View File

@ -69,7 +69,7 @@ private:
xspan_check_range(ptr, base, size_in_bytes);
}
#else
forceinline_constexpr void assertInvariants() const noexcept {}
forceinline void assertInvariants() const noexcept {}
#endif
static inline pointer makeNotNull(pointer p) {
@ -288,49 +288,49 @@ public:
reinterpret_cast<rpointer>(base));
}
bool operator==(pointer other) const { return ptr == other; }
bool operator==(pointer other) const noexcept { return ptr == other; }
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator==(U *other) const {
operator==(U *other) const noexcept {
return ptr == other;
}
bool operator!=(pointer other) const { return ptr != other; }
bool operator!=(pointer other) const noexcept { return ptr != other; }
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator!=(U *other) const {
operator!=(U *other) const noexcept {
return ptr != other;
}
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator==(const PtrOrSpan<U> &other) const {
operator==(const PtrOrSpan<U> &other) const noexcept {
return ptr == other.ptr;
}
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator==(const PtrOrSpanOrNull<U> &other) const {
operator==(const PtrOrSpanOrNull<U> &other) const noexcept {
return ptr == other.ptr;
}
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator==(const Span<U> &other) const {
operator==(const Span<U> &other) const noexcept {
return ptr == other.ptr;
}
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator!=(const PtrOrSpan<U> &other) const {
return !(*this == other);
operator!=(const PtrOrSpan<U> &other) const noexcept {
return ptr != other.ptr;
}
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator!=(const PtrOrSpanOrNull<U> &other) const {
return !(*this == other);
operator!=(const PtrOrSpanOrNull<U> &other) const noexcept {
return ptr != other.ptr;
}
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator!=(const Span<U> &other) const {
return !(*this == other);
operator!=(const Span<U> &other) const noexcept {
return ptr != other.ptr;
}
// check for notNull here

View File

@ -55,7 +55,7 @@ private:
// inverse logic for ensuring valid pointers from existing objects
inline pointer ensurePtr() const { return ptr; }
// debug
forceinline_constexpr void assertInvariants() const noexcept {}
forceinline void assertInvariants() const noexcept {}
public:
#if XSPAN_CONFIG_ENABLE_IMPLICIT_CONVERSION || 1
@ -132,15 +132,15 @@ public:
// comparison
bool operator==(pointer other) const { return ptr == other; }
bool operator==(pointer other) const noexcept { return ptr == other; }
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator==(U *other) const {
operator==(U *other) const noexcept {
return ptr == other;
}
template <class U>
XSPAN_REQUIRES_CONVERTIBLE_R(bool)
operator==(const Ptr<U> &other) const {
operator==(const Ptr<U> &other) const noexcept {
return ptr == other.ptr;
}

View File

@ -87,6 +87,10 @@ public:
// nullptr
forceinline CSelf(std::nullptr_t) noexcept : ptr(nullptr), base(nullptr), size_in_bytes(0) {}
forceinline Self &operator=(std::nullptr_t) noexcept {
ptr = nullptr;
return *this;
}
#undef CSelf
};