summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-09-08 23:09:21 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-09-08 23:09:37 +0200
commit677265461b3c596ab2a88858e74b0970196198fe (patch)
tree40cb1e82e78221dad294b9a521024936c2b716bc /src
parentbf900719174913774e9559302ac90e11c68ac87a (diff)
Make clang-tidy happy
Diffstat (limited to 'src')
-rw-r--r--src/args.cc27
-rw-r--r--src/args.hh6
-rw-r--r--src/main.cc5
-rw-r--r--src/u16.hh4
-rw-r--r--src/u8.hh4
-rw-r--r--src/umod8.hh4
6 files changed, 29 insertions, 21 deletions
diff --git a/src/args.cc b/src/args.cc
index 68f296b..078db1a 100644
--- a/src/args.cc
+++ b/src/args.cc
@@ -1,11 +1,18 @@
#include "args.hh"
+#include <algorithm>
#include <cassert>
+#include <cstddef>
+#include <cstdint>
#include <format>
#include <iostream>
#include <map>
+#include <memory>
#include <optional>
+#include <string>
+#include <string_view>
#include <utility>
+#include <vector>
namespace {
@@ -13,7 +20,7 @@ std::string kEmpty;
class OptionImpl : public Args::OptionArgument {
public:
- enum Type {
+ enum Type : uint8_t {
NoArgument,
RequiredArgument,
OptionalArgument,
@@ -30,11 +37,13 @@ class OptionImpl : public Args::OptionArgument {
const std::string arg;
const std::string help;
- bool is_set() const override { return is_set_; }
+ [[nodiscard]] bool is_set() const override { return is_set_; }
- bool has_argument() const override { return value_.has_value(); }
+ [[nodiscard]] bool has_argument() const override {
+ return value_.has_value();
+ }
- const std::string& argument() const override {
+ [[nodiscard]] const std::string& argument() const override {
if (value_.has_value())
return value_.value();
assert(false);
@@ -117,7 +126,7 @@ class ArgsImpl : public Args {
// "--", no more options signal
if (arguments) {
for (++a; a < argc; ++a)
- arguments->push_back(argv[a]);
+ arguments->emplace_back(argv[a]);
}
break;
}
@@ -193,7 +202,7 @@ class ArgsImpl : public Args {
}
} else {
if (arguments)
- arguments->push_back(argv[a]);
+ arguments->emplace_back(argv[a]);
}
}
return true;
@@ -202,7 +211,7 @@ class ArgsImpl : public Args {
void print_error(std::ostream& out) const override {
if (last_error_.empty()) return;
- out << last_error_ << std::endl;
+ out << last_error_ << '\n';
}
void print_help(std::ostream& out, uint32_t width = 79) const override {
@@ -240,7 +249,7 @@ class ArgsImpl : public Args {
}
need += 2; // margin
- option_need.push_back(need);
+ option_need.emplace_back(need);
if (need <= max_need) {
indent = std::max(indent, need);
}
@@ -309,7 +318,7 @@ class ArgsImpl : public Args {
if (!opt->longname.empty())
long_.emplace(opt->longname, idx);
}
- options_.push_back(std::move(opt));
+ options_.emplace_back(std::move(opt));
}
static inline bool is_whitespace(char c) {
diff --git a/src/args.hh b/src/args.hh
index 75c31b1..2436696 100644
--- a/src/args.hh
+++ b/src/args.hh
@@ -16,7 +16,7 @@ class Args {
public:
virtual ~Option() = default;
- virtual bool is_set() const = 0;
+ [[nodiscard]] virtual bool is_set() const = 0;
protected:
Option() = default;
@@ -26,8 +26,8 @@ class Args {
class OptionArgument : public Option {
public:
- virtual bool has_argument() const = 0;
- virtual const std::string& argument() const = 0;
+ [[nodiscard]] virtual bool has_argument() const = 0;
+ [[nodiscard]] virtual const std::string& argument() const = 0;
};
static std::unique_ptr<Args> create(std::string prgname = std::string());
diff --git a/src/main.cc b/src/main.cc
index 9abed21..27b4854 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -13,7 +13,7 @@ int main(int argc, char** argv) {
auto opt_version = args->option('V', "version", "display version and exit.");
if (!args->run(argc, argv)) {
args->print_error(std::cerr);
- std::cerr << "Try 'jkc --help' for more information." << std::endl;
+ std::cerr << "Try 'jkc --help' for more information.\n";
return 1;
}
if (opt_help->is_set()) {
@@ -21,12 +21,11 @@ int main(int argc, char** argv) {
<< "Java and Kotlin Compiler\n"
<< "\n";
args->print_help(std::cout);
- std::cout << std::flush;
return 0;
}
if (opt_version->is_set()) {
std::cout << "jkc " << VERSION
- << " written by Joel Klinghed <the_jk@spawned.biz>." << std::endl;
+ << " written by Joel Klinghed <the_jk@spawned.biz>.\n";
return 0;
}
return 0;
diff --git a/src/u16.hh b/src/u16.hh
index 6894a84..c23a366 100644
--- a/src/u16.hh
+++ b/src/u16.hh
@@ -1,12 +1,12 @@
#ifndef U16_HH
#define U16_HH
-#include <cstdint>
+#include <cstdint> // IWYU pragma: export
#include <expected>
#include <iterator>
#include <type_traits>
-#include "u.hh"
+#include "u.hh" // IWYU pragma: export
namespace u16 {
diff --git a/src/u8.hh b/src/u8.hh
index 413b156..048af4f 100644
--- a/src/u8.hh
+++ b/src/u8.hh
@@ -1,12 +1,12 @@
#ifndef U8_HH
#define U8_HH
-#include <cstdint>
+#include <cstdint> // IWYU pragma: export
#include <expected>
#include <iterator>
#include <type_traits>
-#include "u.hh"
+#include "u.hh" // IWYU pragma: export
namespace u8 {
diff --git a/src/umod8.hh b/src/umod8.hh
index 8d4fdb2..14406c4 100644
--- a/src/umod8.hh
+++ b/src/umod8.hh
@@ -1,12 +1,12 @@
#ifndef UMOD8_HH
#define UMOD8_HH
-#include <cstdint>
+#include <cstdint> // IWYU pragma: export
#include <expected>
#include <iterator>
#include <type_traits>
-#include "u.hh"
+#include "u.hh" // IWYU pragma: export
namespace umod8 {