diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2016-02-27 19:38:15 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2016-02-27 19:38:15 -0800 |
commit | 10f3ea0008a4563c2baa4f29954c285d2d53d7dc (patch) | |
tree | 8aedadea55a31de188be16a1ec140cdbc76adba5 | |
parent | 88a785e32117081b91b813ac6b5437deb33ef0f7 (diff) |
Mark a bunch of constructors as explicit
This prevents undesired implicit conversions
-rw-r--r-- | src/autoload.h | 2 | ||||
-rw-r--r-- | src/builtin.cpp | 6 | ||||
-rw-r--r-- | src/builtin.h | 2 | ||||
-rw-r--r-- | src/builtin_printf.cpp | 2 | ||||
-rw-r--r-- | src/builtin_test.cpp | 2 | ||||
-rw-r--r-- | src/common.h | 16 | ||||
-rw-r--r-- | src/complete.h | 2 | ||||
-rw-r--r-- | src/env.h | 5 | ||||
-rw-r--r-- | src/env_universal_common.cpp | 4 | ||||
-rw-r--r-- | src/env_universal_common.h | 2 | ||||
-rw-r--r-- | src/event.h | 2 | ||||
-rw-r--r-- | src/fish_tests.cpp | 2 | ||||
-rw-r--r-- | src/history.cpp | 6 | ||||
-rw-r--r-- | src/history.h | 4 | ||||
-rw-r--r-- | src/io.h | 6 | ||||
-rw-r--r-- | src/lru.h | 6 | ||||
-rw-r--r-- | src/parse_tree.cpp | 2 | ||||
-rw-r--r-- | src/parser.h | 8 | ||||
-rw-r--r-- | src/proc.cpp | 29 | ||||
-rw-r--r-- | src/proc.h | 2 | ||||
-rw-r--r-- | src/screen.cpp | 2 | ||||
-rw-r--r-- | src/tokenizer.h | 2 |
22 files changed, 45 insertions, 69 deletions
diff --git a/src/autoload.h b/src/autoload.h index c364a4c3..f0ad9d03 100644 --- a/src/autoload.h +++ b/src/autoload.h @@ -27,7 +27,7 @@ file_access_attempt_t access_file(const wcstring &path, int mode); struct autoload_function_t : public lru_node_t { - autoload_function_t(const wcstring &key) : lru_node_t(key), access(), is_loaded(false), is_placeholder(false), is_internalized(false) { } + explicit autoload_function_t(const wcstring &key) : lru_node_t(key), access(), is_loaded(false), is_placeholder(false), is_internalized(false) { } file_access_attempt_t access; /** The last access attempt */ bool is_loaded; /** Whether we have actually loaded this function */ bool is_placeholder; /** Whether we are a placeholder that stands in for "no such function". If this is true, then is_loaded must be false. */ diff --git a/src/builtin.cpp b/src/builtin.cpp index a4363e4b..b83bb82a 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -2805,7 +2805,7 @@ static int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) wcstring tokens; tokens.reserve(buff.size()); bool empty = true; - + for (wcstring_range loc = wcstring_tok(buff, ifs); loc.first != wcstring::npos; loc = wcstring_tok(buff, ifs, loc)) { if (!empty) tokens.push_back(ARRAY_SEP); @@ -2820,7 +2820,7 @@ static int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) while (i<argc) { - loc = wcstring_tok(buff, (i+1<argc) ? ifs : L"", loc); + loc = wcstring_tok(buff, (i+1<argc) ? ifs : wcstring(), loc); env_set(argv[i], loc.first == wcstring::npos ? L"" : &buff.c_str()[loc.first], place); ++i; @@ -3141,7 +3141,7 @@ static int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) } else { - dir_in = argv[1]; + dir_in = env_var_t(argv[1]); } bool got_cd_path = false; diff --git a/src/builtin.h b/src/builtin.h index 859c4874..f747eb9b 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -126,7 +126,7 @@ class builtin_commandline_scoped_transient_t { size_t token; public: - builtin_commandline_scoped_transient_t(const wcstring &cmd); + explicit builtin_commandline_scoped_transient_t(const wcstring &cmd); ~builtin_commandline_scoped_transient_t(); }; diff --git a/src/builtin_printf.cpp b/src/builtin_printf.cpp index b2bcfc7c..d5fa1d63 100644 --- a/src/builtin_printf.cpp +++ b/src/builtin_printf.cpp @@ -66,7 +66,7 @@ struct builtin_printf_state_t /* Whether we should stop outputting. This gets set in the case of an error, and also with the \c escape. */ bool early_exit; - builtin_printf_state_t(io_streams_t &s) : streams(s), exit_code(0), early_exit(false) + explicit builtin_printf_state_t(io_streams_t &s) : streams(s), exit_code(0), early_exit(false) { } diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index e80d06ec..00fb8860 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -173,7 +173,7 @@ private: } public: - test_parser(const wcstring_list_t &val) : strings(val) + explicit test_parser(const wcstring_list_t &val) : strings(val) { } expression *parse_expression(unsigned int start, unsigned int end); diff --git a/src/common.h b/src/common.h index ff7443e5..660bc012 100644 --- a/src/common.h +++ b/src/common.h @@ -357,7 +357,7 @@ struct string_fuzzy_match_t size_t match_distance_second; /* Constructor */ - string_fuzzy_match_t(enum fuzzy_match_type_t t, size_t distance_first = 0, size_t distance_second = 0); + explicit string_fuzzy_match_t(enum fuzzy_match_type_t t, size_t distance_first = 0, size_t distance_second = 0); /* Return -1, 0, 1 if this match is (respectively) better than, equal to, or worse than rhs */ int compare(const string_fuzzy_match_t &rhs) const; @@ -486,7 +486,7 @@ class null_terminated_array_t public: null_terminated_array_t() : array(NULL) { } - null_terminated_array_t(const string_list_t &argv) : array(make_null_terminated_array(argv)) + explicit null_terminated_array_t(const string_list_t &argv) : array(make_null_terminated_array(argv)) { } @@ -576,8 +576,8 @@ class scoped_lock public: void lock(void); void unlock(void); - scoped_lock(pthread_mutex_t &mutex); - scoped_lock(mutex_lock_t &lock); + explicit scoped_lock(pthread_mutex_t &mutex); + explicit scoped_lock(mutex_lock_t &lock); ~scoped_lock(); }; @@ -607,7 +607,7 @@ class scoped_rwlock /* No copying */ scoped_rwlock &operator=(const scoped_lock &); - scoped_rwlock(const scoped_lock &); + explicit scoped_rwlock(const scoped_lock &); public: void lock(void); @@ -619,8 +619,8 @@ public: equivalent to `lock.unlock_shared(); lock.lock();` */ void upgrade(void); - scoped_rwlock(pthread_rwlock_t &rwlock, bool shared = false); - scoped_rwlock(rwlock_t &rwlock, bool shared = false); + explicit scoped_rwlock(pthread_rwlock_t &rwlock, bool shared = false); + explicit scoped_rwlock(rwlock_t &rwlock, bool shared = false); ~scoped_rwlock(); }; @@ -639,7 +639,7 @@ class scoped_push bool restored; public: - scoped_push(T *r): ref(r), saved_value(*r), restored(false) + explicit scoped_push(T *r): ref(r), saved_value(*r), restored(false) { } diff --git a/src/complete.h b/src/complete.h index f46370ab..6cbb13bc 100644 --- a/src/complete.h +++ b/src/complete.h @@ -111,7 +111,7 @@ public: complete_flags_t flags; /* Construction. Note: defining these so that they are not inlined reduces the executable size. */ - completion_t(const wcstring &comp, const wcstring &desc = wcstring(), string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact), complete_flags_t flags_val = 0); + explicit completion_t(const wcstring &comp, const wcstring &desc = wcstring(), string_fuzzy_match_t match = string_fuzzy_match_t(fuzzy_match_exact), complete_flags_t flags_val = 0); completion_t(const completion_t &); completion_t &operator=(const completion_t &); @@ -101,12 +101,11 @@ class env_var_t : public wcstring private: bool is_missing; public: - static env_var_t missing_var(void) + static env_var_t missing_var() { - env_var_t result(L""); + env_var_t result((wcstring())); result.is_missing = true; return result; - } env_var_t(const env_var_t &x) : wcstring(x), is_missing(x.is_missing) { } diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index bb181504..f7c07ea2 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -338,7 +338,7 @@ env_var_t env_universal_t::get(const wcstring &name) const var_table_t::const_iterator where = vars.find(name); if (where != vars.end()) { - result = where->second.val; + result = env_var_t(where->second.val); } return result; } @@ -1454,7 +1454,7 @@ class universal_notifier_named_pipe_t : public universal_notifier_t } public: - universal_notifier_named_pipe_t(const wchar_t *test_path) : pipe_fd(-1), readback_time_usec(0), readback_amount(0), polling_due_to_readable_fd(false), drain_if_still_readable_time_usec(0) + explicit universal_notifier_named_pipe_t(const wchar_t *test_path) : pipe_fd(-1), readback_time_usec(0), readback_amount(0), polling_due_to_readable_fd(false), drain_if_still_readable_time_usec(0) { make_pipe(test_path); } diff --git a/src/env_universal_common.h b/src/env_universal_common.h index 3428c693..60cf0027 100644 --- a/src/env_universal_common.h +++ b/src/env_universal_common.h @@ -75,7 +75,7 @@ class env_universal_t static var_table_t read_message_internal(int fd); public: - env_universal_t(const wcstring &path); + explicit env_universal_t(const wcstring &path); ~env_universal_t(); /* Get the value of the variable with the specified name */ diff --git a/src/event.h b/src/event.h index 80737596..bf068c5d 100644 --- a/src/event.h +++ b/src/event.h @@ -87,7 +87,7 @@ public: */ wcstring_list_t arguments; - event_t(int t); + explicit event_t(int t); ~event_t(); static event_t signal_event(int sig); diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index adbc13a5..efc134d7 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1318,7 +1318,7 @@ static void test_escape_sequences(void) class lru_node_test_t : public lru_node_t { public: - lru_node_test_t(const wcstring &tmp) : lru_node_t(tmp) { } + explicit lru_node_test_t(const wcstring &tmp) : lru_node_t(tmp) { } }; class test_lru_t : public lru_cache_t<lru_node_test_t> diff --git a/src/history.cpp b/src/history.cpp index 112af1ea..28be7bc5 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -129,7 +129,7 @@ class time_profiler_t double start; public: - time_profiler_t(const char *w) + explicit time_profiler_t(const char *w) { if (LOG_TIMES) { @@ -165,7 +165,7 @@ class history_lru_node_t : public lru_node_t public: time_t timestamp; path_list_t required_paths; - history_lru_node_t(const history_item_t &item) : + explicit history_lru_node_t(const history_item_t &item) : lru_node_t(item.str()), timestamp(item.timestamp()), required_paths(item.required_paths) @@ -183,7 +183,7 @@ protected: } public: - history_lru_cache_t(size_t max) : lru_cache_t<history_lru_node_t>(max) { } + explicit history_lru_cache_t(size_t max) : lru_cache_t<history_lru_node_t>(max) { } /* Function to add a history item */ void add_item(const history_item_t &item) diff --git a/src/history.h b/src/history.h index 63372ba0..f99950aa 100644 --- a/src/history.h +++ b/src/history.h @@ -116,7 +116,7 @@ private: history_t &operator=(const history_t&); /** Private creator */ - history_t(const wcstring &pname); + explicit history_t(const wcstring &pname); /** Privately add an item. If pending, the item will not be returned by history searches until a call to resolve_pending. */ void add(const history_item_t &item, bool pending = false); @@ -348,7 +348,7 @@ void history_sanity_check(); struct file_detection_context_t { /* Constructor */ - file_detection_context_t(history_t *hist, history_identifier_t ident = 0); + explicit file_detection_context_t(history_t *hist, history_identifier_t ident = 0); /* Determine which of potential_paths are valid, and put them in valid_paths */ int perform_file_detection(); @@ -56,7 +56,7 @@ public: class io_close_t : public io_data_t { public: - io_close_t(int f) : + explicit io_close_t(int f) : io_data_t(IO_CLOSE, f) { } @@ -137,7 +137,7 @@ private: /** buffer to save output in */ std::vector<char> out_buffer; - io_buffer_t(int f): + explicit io_buffer_t(int f): io_pipe_t(IO_BUFFER, f, false /* not input */), out_buffer() { @@ -195,7 +195,7 @@ class io_chain_t : public std::vector<shared_ptr<io_data_t> > { public: io_chain_t(); - io_chain_t(const shared_ptr<io_data_t> &); + explicit io_chain_t(const shared_ptr<io_data_t> &); void remove(const shared_ptr<const io_data_t> &element); void push_back(const shared_ptr<io_data_t> &element); @@ -35,7 +35,7 @@ public: const wcstring key; /** Constructor */ - lru_node_t(const wcstring &pkey) : prev(NULL), next(NULL), key(pkey) { } + explicit lru_node_t(const wcstring &pkey) : prev(NULL), next(NULL), key(pkey) { } /** Virtual destructor that does nothing for classes that inherit lru_node_t */ virtual ~lru_node_t() {} @@ -117,7 +117,7 @@ protected: public: /** Constructor */ - lru_cache_t(size_t max_size = 1024) : max_node_count(max_size), node_count(0), mouth(wcstring()) + explicit lru_cache_t(size_t max_size = 1024) : max_node_count(max_size), node_count(0), mouth(wcstring()) { /* Hook up the mouth to itself: a one node circularly linked list! */ mouth.prev = mouth.next = &mouth; @@ -220,7 +220,7 @@ public: { lru_node_t *node; public: - iterator(lru_node_t *val) : node(val) { } + explicit iterator(lru_node_t *val) : node(val) { } void operator++() { node = lru_cache_t::get_previous(node); diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index ead78a6e..5939e270 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -628,7 +628,7 @@ class parse_ll_t public: /* Constructor */ - parse_ll_t(enum parse_token_type_t goal) : fatal_errored(false), should_generate_error_messages(true) + explicit parse_ll_t(enum parse_token_type_t goal) : fatal_errored(false), should_generate_error_messages(true) { this->symbol_stack.reserve(16); this->nodes.reserve(64); diff --git a/src/parser.h b/src/parser.h index 1b2bad1b..db35471b 100644 --- a/src/parser.h +++ b/src/parser.h @@ -85,7 +85,7 @@ struct block_t { protected: /** Protected constructor. Use one of the subclasses below. */ - block_t(block_type_t t); + explicit block_t(block_type_t t); private: const block_type_t block_type; /**< Type of block. */ @@ -134,7 +134,7 @@ struct if_block_t : public block_t struct event_block_t : public block_t { event_t const event; - event_block_t(const event_t &evt); + explicit event_block_t(const event_t &evt); }; struct function_block_t : public block_t @@ -147,7 +147,7 @@ struct function_block_t : public block_t struct source_block_t : public block_t { const wchar_t * const source_file; - source_block_t(const wchar_t *src); + explicit source_block_t(const wchar_t *src); }; struct for_block_t : public block_t @@ -172,7 +172,7 @@ struct fake_block_t : public block_t struct scope_block_t : public block_t { - scope_block_t(block_type_t type); //must be BEGIN, TOP or SUBST + explicit scope_block_t(block_type_t type); //must be BEGIN, TOP or SUBST }; struct breakpoint_block_t : public block_t diff --git a/src/proc.cpp b/src/proc.cpp index 0a0da0a8..e16688f0 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -354,8 +354,6 @@ int job_signal(job_t *j, int signal) /** Store the status of the process pid that was returned by waitpid. - Return 0 if all went well, nonzero otherwise. - This is called from a signal handler. */ static void mark_process_status(const job_t *j, process_t *p, int status) { @@ -374,18 +372,7 @@ static void mark_process_status(const job_t *j, process_t *p, int status) { /* This should never be reached */ p->completed = 1; - - char mess[MESS_SIZE]; - snprintf(mess, - MESS_SIZE, - "Process %ld exited abnormally\n", - (long) p->pid); - /* - If write fails, do nothing. We're in a signal handlers error - handler. If things aren't working properly, it's safer to - give up. - */ - write_ignore(2, mess, strlen(mess)); + fprintf(stderr, "Process %ld exited abnormally\n", (long)p->pid); } } @@ -399,10 +386,8 @@ void job_mark_process_as_failed(const job_t *job, process_t *p) } /** - Handle status update for child \c pid. This function is called by - the signal handler, so it mustn't use malloc or any such hitech - nonsense. - + Handle status update for child \c pid. + \param pid the pid of the process whose status changes \param status the status as returned by wait */ @@ -411,14 +396,6 @@ static void handle_child_status(pid_t pid, int status) bool found_proc = false; const job_t *j = NULL; process_t *p = NULL; -// char mess[MESS_SIZE]; - /* - snprintf( mess, - MESS_SIZE, - "Process %d\n", - (int) pid ); - write( 2, mess, strlen(mess )); - */ job_iterator_t jobs; while (! found_proc && (j = jobs.next())) @@ -422,7 +422,7 @@ public: return job; } - job_iterator_t(job_list_t &jobs); + explicit job_iterator_t(job_list_t &jobs); job_iterator_t(); size_t count() const; }; diff --git a/src/screen.cpp b/src/screen.cpp index dc78d227..7bb5cf4b 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -74,7 +74,7 @@ class scoped_buffer_t int (* const old_writer)(char); public: - scoped_buffer_t(data_buffer_t *buff) : old_buff(s_writeb_buffer), old_writer(output_get_writer()) + explicit scoped_buffer_t(data_buffer_t *buff) : old_buff(s_writeb_buffer), old_writer(output_get_writer()) { s_writeb_buffer = buff; output_set_writer(s_writeb); diff --git a/src/tokenizer.h b/src/tokenizer.h index d88feef6..d6de2559 100644 --- a/src/tokenizer.h +++ b/src/tokenizer.h @@ -195,7 +195,7 @@ private: public: - move_word_state_machine_t(move_word_style_t st); + explicit move_word_state_machine_t(move_word_style_t st); bool consume_char(wchar_t c); void reset(); }; |