Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial clang-tidy configuration #1253

Merged
merged 10 commits into from
Sep 24, 2024
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Checks: 'performance-*, modernize-*, misc-*, -misc-definitions-in-headers, -misc-non-private-member-variables-in-classes, -misc-no-recursion, -misc-include-cleaner, -misc-use-anonymous-namespace, -modernize-use-trailing-return-type, -modernize-use-nodiscard, -modernize-use-emplace, -modernize-loop-convert, -modernize-pass-by-value, -modernize-use-equals-delete, -modernize-use-equals-default, -modernize-use-override, -modernize-avoid-c-arrays, -modernize-raw-string-literal, -modernize-concat-nested-namespaces, -performance-inefficient-string-concatenation'
4 changes: 2 additions & 2 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1859,12 +1859,12 @@ constexpr auto is_narrowing_v =
// [dcl.init.list] 7.1
(std::is_floating_point_v<From> && std::is_integral_v<To>) ||
// [dcl.init.list] 7.2
(std::is_floating_point_v<From> && std::is_floating_point_v<To> && sizeof(From) > sizeof(To)) ||
(std::is_floating_point_v<From> && std::is_floating_point_v<To> && sizeof(From) > sizeof(To)) || // NOLINT(misc-redundant-expression)
// [dcl.init.list] 7.3
(std::is_integral_v<From> && std::is_floating_point_v<To>) ||
(std::is_enum_v<From> && std::is_floating_point_v<To>) ||
// [dcl.init.list] 7.4
(std::is_integral_v<From> && std::is_integral_v<To> && sizeof(From) > sizeof(To)) ||
(std::is_integral_v<From> && std::is_integral_v<To> && sizeof(From) > sizeof(To)) || // NOLINT(misc-redundant-expression)
(std::is_enum_v<From> && std::is_integral_v<To> && sizeof(From) > sizeof(To)) ||
// [dcl.init.list] 7.5
(std::is_pointer_v<From> && std::is_same_v<To, bool>)
Expand Down
10 changes: 5 additions & 5 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct source_line
{
std::string text;

enum class category { empty, preprocessor, comment, import, cpp1, cpp2, rawstring };
enum class category : u8 { empty, preprocessor, comment, import, cpp1, cpp2, rawstring };
category cat;

bool all_tokens_are_densely_spaced = true; // to be overridden in lexing if they're not
Expand Down Expand Up @@ -128,7 +128,7 @@ struct source_position

struct comment
{
enum class comment_kind { line_comment = 0, stream_comment };
enum class comment_kind : u8 { line_comment = 0, stream_comment };

comment_kind kind;
source_position start;
Expand All @@ -141,7 +141,7 @@ struct comment
struct string_parts {
struct cpp_code { std::string text; };
struct raw_string { std::string text; };
enum adds_sequences { no_ends = 0, on_the_beginning = 1, on_the_end = 2, on_both_ends = 3 };
enum adds_sequences : u8 { no_ends = 0, on_the_beginning = 1, on_the_end = 2, on_both_ends = 3 };

string_parts(const std::string& beginseq,
const std::string& endseq,
Expand Down Expand Up @@ -892,8 +892,8 @@ class cmdline_processor
-> void
{
help_requested = true;
std::string_view a = __DATE__;
std::string_view b = __TIME__;
constexpr std::string_view a = __DATE__;
constexpr std::string_view b = __TIME__;
std::unordered_map<std::string_view, char> m = { {"Jan",'1'}, {"Feb",'2'}, {"Mar",'3'}, {"Apr",'4'}, {"May",'5'}, {"Jun",'6'}, {"Jul",'7'}, {"Aug",'8'}, {"Sep",'9'}, {"Oct",'A'}, {"Nov",'B'}, {"Dec",'C'} };
farmerpiki marked this conversation as resolved.
Show resolved Hide resolved

auto stamp = std::to_string(atoi(&a[9])-15);
Expand Down
4 changes: 2 additions & 2 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ auto main(
}
else {
std::cerr << arg.text << " - ambiguous compiler flag name, did you mean one of these?\n";
for (auto a : ambiguous) {
for (auto const& a : ambiguous) {
std::cerr << " " << arg.text.front() << a << "\n";
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ auto main(
auto total_time = print_with_thousands(t.elapsed().count());
std::cout << "\n Time " << total_time << " ms";

std::multimap< long long, std::string_view, std::greater<long long> > sorted_timers;
std::multimap< long long, std::string_view, std::greater<> > sorted_timers;
for (auto [name, t] : timers) {
sorted_timers.insert({t.elapsed().count(), name});
}
Expand Down
7 changes: 3 additions & 4 deletions source/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class braces_tracker
//
// line current line being processed
//
enum class preprocessor_conditional {
enum class preprocessor_conditional : u8 {
none = 0, pre_if, pre_else, pre_endif
};
auto starts_with_preprocessor_if_else_endif(
Expand Down Expand Up @@ -635,7 +635,7 @@ auto process_cpp_line(
i+=2;
if (i < ssize(line) - 1)
{
if (auto paren_pos = line.find("(", i);
if (auto paren_pos = line.find('(', i);
paren_pos != line.npos
)
{
Expand Down Expand Up @@ -841,7 +841,7 @@ class source
static const int max_line_len = 90'000;
// do not reduce this - I encountered an 80,556-char
// line in real world code during testing
char buf[max_line_len];
char buf[max_line_len] {0};

public:
//-----------------------------------------------------------------------
Expand All @@ -854,7 +854,6 @@ class source
)
: errors{ errors_ }
, lines( 1 ) // extra blank to avoid off-by-one everywhere
, buf{0}
{
}

Expand Down
6 changes: 3 additions & 3 deletions source/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace cpp2 {
//-----------------------------------------------------------------------
//

enum class lexeme : std::int8_t {
enum class lexeme : i8 {
SlashEq,
Slash,
LeftShiftEq,
Expand Down Expand Up @@ -1496,7 +1496,7 @@ auto lex_line(
auto R_pos = i + 1;
auto seq_pos = i + 3;

if (auto paren_pos = line.find("(", seq_pos); paren_pos != line.npos) {
if (auto paren_pos = line.find('(', seq_pos); paren_pos != line.npos) {
auto opening_seq = line.substr(i, paren_pos - i + 1);
auto closing_seq = ")"+line.substr(seq_pos, paren_pos-seq_pos)+"\"";

Expand Down Expand Up @@ -1717,7 +1717,7 @@ auto lex_line(
if (peek(j-2) == 'R') {
auto seq_pos = i + j;

if (auto paren_pos = line.find("(", seq_pos); paren_pos != line.npos) {
if (auto paren_pos = line.find('(', seq_pos); paren_pos != line.npos) {
auto opening_seq = line.substr(i, paren_pos - i + 1);
auto closing_seq = ")"+line.substr(seq_pos, paren_pos-seq_pos)+"\"";

Expand Down
30 changes: 15 additions & 15 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct template_argument;

struct primary_expression_node
{
enum active { empty=0, identifier, expression_list, id_expression, declaration, inspect, literal };
enum active : u8 { empty=0, identifier, expression_list, id_expression, declaration, inspect, literal };
std::variant<
std::monostate,
token const*,
Expand Down Expand Up @@ -669,7 +669,7 @@ auto binary_expression_node<Name, Term>::is_standalone_expression() const
}


enum class passing_style { in=0, copy, inout, out, move, forward, invalid };
enum class passing_style : u8 { in=0, copy, inout, out, move, forward, invalid };
auto to_passing_style(token const& t) -> passing_style {
if (t.type() == lexeme::Identifier) {
if (t == "in" ) { return passing_style::in; }
Expand Down Expand Up @@ -1179,7 +1179,7 @@ struct template_args_tag { };

struct template_argument
{
enum active { empty=0, expression, type_id };
enum active : u8 { empty=0, expression, type_id };
source_position comma;
std::variant<
std::monostate,
Expand Down Expand Up @@ -1365,7 +1365,7 @@ struct type_id_node
int dereference_cnt = {};
token const* suspicious_initialization = {};

enum active { empty=0, qualified, unqualified, function, keyword };
enum active : u8 { empty=0, qualified, unqualified, function, keyword };
std::variant<
std::monostate,
std::unique_ptr<qualified_id_node>,
Expand Down Expand Up @@ -1666,7 +1666,7 @@ struct id_expression_node
{
source_position pos;

enum active { empty=0, qualified, unqualified };
enum active : u8 { empty=0, qualified, unqualified };
std::variant<
std::monostate,
std::unique_ptr<qualified_id_node>,
Expand Down Expand Up @@ -2153,7 +2153,7 @@ struct statement_node
// type(s) used in a std::unique_ptr as a member
~statement_node();

enum active { expression=0, compound, selection, declaration, return_, iteration, using_, contract, inspect, jump };
enum active : u8 { expression=0, compound, selection, declaration, return_, iteration, using_, contract, inspect, jump };
std::variant<
std::unique_ptr<expression_statement_node>,
std::unique_ptr<compound_statement_node>,
Expand Down Expand Up @@ -2281,7 +2281,7 @@ struct parameter_declaration_node
passing_style pass = passing_style::in;
int ordinal = 1;

enum class modifier { none=0, implicit, virtual_, override_, final_ };
enum class modifier : u8 { none=0, implicit, virtual_, override_, final_ };
modifier mod = modifier::none;

std::unique_ptr<declaration_node> declaration;
Expand Down Expand Up @@ -2483,7 +2483,7 @@ struct function_type_node
passing_style pass = passing_style::move;
};

enum active { empty = 0, id, list };
enum active : u8 { empty = 0, id, list };
std::variant<
std::monostate,
single_type_id,
Expand Down Expand Up @@ -2862,7 +2862,7 @@ struct alias_node
token const* type = {};
std::unique_ptr<type_id_node> type_id; // for objects

enum active : std::uint8_t { a_type, a_namespace, an_object };
enum active : u8 { a_type, a_namespace, an_object };
std::variant<
std::unique_ptr<type_id_node>,
std::unique_ptr<id_expression_node>,
Expand Down Expand Up @@ -2903,7 +2903,7 @@ struct alias_node
};


enum class accessibility { default_ = 0, public_, protected_, private_ };
enum class accessibility : u8 { default_ = 0, public_, protected_, private_ };

auto to_string(accessibility a)
-> std::string
Expand Down Expand Up @@ -2932,7 +2932,7 @@ struct declaration_node
std::unique_ptr<unqualified_id_node> identifier;
accessibility access = accessibility::default_;

enum active : std::uint8_t { a_function, an_object, a_type, a_namespace, an_alias };
enum active : u8 { a_function, an_object, a_type, a_namespace, an_alias };
std::variant<
std::unique_ptr<function_type_node>,
std::unique_ptr<type_id_node>,
Expand Down Expand Up @@ -3353,7 +3353,7 @@ struct declaration_node
auto parent_is_polymorphic() const -> bool
{ return parent_declaration && parent_declaration->is_polymorphic(); }

enum which {
enum which : u8 {
functions = 1,
objects = 2,
types = 4,
Expand Down Expand Up @@ -3421,7 +3421,7 @@ struct declaration_node
{
// Convert the gather_ results to const*
auto tmp = gather_type_scope_declarations(w);
return std::vector<declaration_node const*>(tmp.begin(), tmp.end());
return {tmp.begin(), tmp.end()};
}


Expand Down Expand Up @@ -6105,7 +6105,7 @@ class parser
// Remember current position, because we may need to backtrack
auto start_pos = pos;

bool inside_initializer = (
const bool inside_initializer = (
peek(-1) && peek(-1)->type() == lexeme::Assignment
);
auto open_paren = &curr();
Expand Down Expand Up @@ -8069,7 +8069,7 @@ class parser
)
-> std::unique_ptr<compound_statement_node>
{
bool is_braced = curr().type() == lexeme::LeftBrace;
const bool is_braced = curr().type() == lexeme::LeftBrace;
if (
!is_braced
&& !allow_single_unbraced_statement
Expand Down
Loading
Loading