Fixed many compiler warnings from g++ 4.4

This commit is contained in:
John Wiegley 2009-10-25 04:35:19 -04:00
parent dc66840dd7
commit 588f2ef2f5
28 changed files with 150 additions and 123 deletions

View file

@ -88,7 +88,7 @@ AC_CACHE_CHECK(
if (status < 0) {
;
} else if (status == 0) {
char *arg0;
char *arg0 = NULL;
status = dup2(pfd[0], STDIN_FILENO);
@ -160,8 +160,8 @@ AC_CACHE_CHECK(
[[#include <stdlib.h>
#include <stdio.h>
#include <editline/readline.h>]],
[[rl_readline_name = "foo";
char * line = readline("foo: ");
[[rl_readline_name = const_cast<char *>("foo");
char * line = readline(const_cast<char *>("foo: "));
free(line);]])],[libedit_avail_cv_=true],[libedit_avail_cv_=false])
AC_LANG_POP
LIBS=$libedit_save_libs])

View file

@ -53,7 +53,7 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num)
if (*p == '%') {
const char * q = p + 1;
if (*q && *q != '%' && std::isdigit(*q) &&
std::size_t(*q - '0') == index) {
std::string::size_type(*q - '0') == index) {
p++;
buf << std::string(s, num);
matched = true;

View file

@ -56,8 +56,8 @@ namespace ledger {
class straccbuf : public std::streambuf
{
protected:
std::string str; // accumulator
std::size_t index;
std::string str; // accumulator
std::string::size_type index;
public:
straccbuf() : index(0) {}

View file

@ -623,9 +623,9 @@ namespace {
"mpfr_print = " << buf << " (precision " << prec << ")");
if (zeros_prec >= 0) {
int index = std::strlen(buf);
int point = 0;
for (int i = 0; i < index; i++) {
string::size_type index = std::strlen(buf);
string::size_type point = 0;
for (string::size_type i = 0; i < index; i++) {
if (buf[i] == '.') {
point = i;
break;
@ -837,7 +837,7 @@ namespace {
READ_INTO(in, buf, 255, c,
std::isdigit(c) || c == '-' || c == '.' || c == ',');
int len = std::strlen(buf);
string::size_type len = std::strlen(buf);
while (len > 0 && ! std::isdigit(buf[len - 1])) {
buf[--len] = '\0';
in.unget();
@ -989,7 +989,7 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
// necessary.
if (last_comma != string::npos || last_period != string::npos) {
int len = quant.length();
string::size_type len = quant.length();
scoped_array<char> buf(new char[len + 1]);
const char * p = quant.c_str();
char * t = buf.get();

View file

@ -65,10 +65,10 @@ post_handler_ptr chain_post_handlers(report_t& report,
if (report.HANDLED(head_) || report.HANDLED(tail_))
handler.reset
(new truncate_xacts(handler,
report.HANDLED(head_) ?
report.HANDLER(head_).value.to_long() : 0,
report.HANDLED(tail_) ?
report.HANDLER(tail_).value.to_long() : 0));
report.HANDLED(head_) ?
report.HANDLER(head_).value.to_int() : 0,
report.HANDLED(tail_) ?
report.HANDLER(tail_).value.to_int() : 0));
// filter_posts will only pass through posts matching the
// `display_predicate'.

View file

@ -498,10 +498,9 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
char * _p = buf;
c = static_cast<char>(in.peek());
while (_p - buf < 255 && in.good() && ! in.eof() && c != '\n') {
int bytes = 0;
int size = _p - buf;
unsigned char d = c;
std::size_t bytes = 0;
std::ptrdiff_t size = _p - buf;
unsigned char d = c;
// Check for the start of a UTF-8 multi-byte encoded string
if (d >= 192 && d <= 223 && size < 254)
@ -518,7 +517,7 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
break;
if (bytes > 0) { // we're looking at a UTF-8 encoding
for (int i = 0; i < bytes; i++) {
for (std::size_t i = 0; i < bytes; i++) {
in.get(c);
if (in.bad() || in.eof())
break;

View file

@ -41,7 +41,7 @@ namespace ledger {
void format_emacs_posts::write_xact(xact_t& xact)
{
out << "\"" << xact.pathname << "\" "
<< (static_cast<std::size_t>(xact.beg_line) + 1) << " ";
<< (xact.beg_line + 1) << " ";
tm when = gregorian::to_tm(xact.date());
std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local?
@ -77,7 +77,7 @@ void format_emacs_posts::operator()(post_t& post)
out << "\n";
}
out << " (" << (static_cast<std::size_t>(post.beg_line) + 1) << " ";
out << " (" << (post.beg_line + 1) << " ";
out << "\"" << post.reported_account()->fullname() << "\" \""
<< post.amount << "\"";

View file

@ -47,16 +47,16 @@ string error_context()
return context;
}
string file_context(const path& file, std::size_t line)
string file_context(const path& file, const std::size_t line)
{
std::ostringstream buf;
buf << "\"" << file << "\", line " << line << ": ";
return buf.str();
}
string line_context(const string& line,
std::size_t pos,
std::size_t end_pos)
string line_context(const string& line,
const string::size_type pos,
const string::size_type end_pos)
{
std::ostringstream buf;
buf << " " << line << "\n";
@ -64,11 +64,11 @@ string line_context(const string& line,
if (pos != 0) {
buf << " ";
if (end_pos == 0) {
for (std::size_t i = 0; i < pos; i += 1)
for (string::size_type i = 0; i < pos; i += 1)
buf << " ";
buf << "^";
} else {
for (std::size_t i = 0; i < end_pos; i += 1) {
for (string::size_type i = 0; i < end_pos; i += 1) {
if (i >= pos)
buf << "^";
else
@ -79,12 +79,12 @@ string line_context(const string& line,
return buf.str();
}
string source_context(const path& file,
istream_pos_type pos,
istream_pos_type end_pos,
const string& prefix)
string source_context(const path& file,
const istream_pos_type pos,
const istream_pos_type end_pos,
const string& prefix)
{
std::streamoff len = end_pos - pos;
const std::streamoff len = end_pos - pos;
if (! len || file == path("/dev/stdin"))
return _("<no source context>");
@ -97,10 +97,9 @@ string source_context(const path& file,
in.seekg(pos, std::ios::beg);
scoped_array<char> buf(new char[len + 1]);
in.read(buf.get(), static_cast<int>(len));
assert(static_cast<std::size_t>(in.gcount()) ==
static_cast<std::size_t>(len));
buf[static_cast<int>(len)] = '\0';
in.read(buf.get(), len);
assert(in.gcount() == len);
buf[len] = '\0';
bool first = true;
for (char * p = std::strtok(buf.get(), "\n");

View file

@ -87,14 +87,14 @@ extern std::ostringstream _ctxt_buffer;
string error_context();
string file_context(const path& file, std::size_t line);
string line_context(const string& line,
std::size_t pos = 0,
std::size_t end_pos = 0);
string line_context(const string& line,
const string::size_type pos = 0,
const string::size_type end_pos = 0);
string source_context(const path& file,
istream_pos_type pos,
istream_pos_type end_pos,
const string& prefix = "");
string source_context(const path& file,
const istream_pos_type pos,
const istream_pos_type end_pos,
const string& prefix = "");
#define DECLARE_EXCEPTION(name, kind) \
class name : public kind { \

View file

@ -142,7 +142,8 @@ class truncate_xacts : public item_handler<post_t>
truncate_xacts();
public:
truncate_xacts(post_handler_ptr handler, int _head_count, int _tail_count)
truncate_xacts(post_handler_ptr handler,
int _head_count, int _tail_count)
: item_handler<post_t>(handler),
head_count(_head_count), tail_count(_tail_count),
xacts_seen(0), last_xact(NULL) {

View file

@ -345,7 +345,7 @@ void format_t::format(std::ostream& out_str, scope_t& scope)
}
DEBUG("format.expr", "value = (" << value << ")");
value.print(out, elem->min_width, -1,
value.print(out, static_cast<int>(elem->min_width), -1,
! elem->has_flags(ELEMENT_ALIGN_LEFT));
}
catch (const calc_error&) {
@ -362,14 +362,13 @@ void format_t::format(std::ostream& out_str, scope_t& scope)
if (elem->max_width > 0 || elem->min_width > 0) {
unistring temp(out.str());
string result;
string result;
if (elem->max_width > 0 && elem->max_width < temp.length()) {
result = truncate(temp, elem->max_width);
} else {
result = temp.extract();
for (int i = 0; i < (static_cast<int>(elem->min_width) -
static_cast<int>(temp.length())); i++)
for (std::size_t i = 0; i < elem->min_width - temp.length(); i++)
result += " ";
}
out_str << result;
@ -379,8 +378,9 @@ void format_t::format(std::ostream& out_str, scope_t& scope)
}
}
string format_t::truncate(const unistring& ustr, std::size_t width,
const int account_abbrev_length)
string format_t::truncate(const unistring& ustr,
const std::size_t width,
const std::size_t account_abbrev_length)
{
assert(width < 4095);
@ -434,7 +434,7 @@ string format_t::truncate(const unistring& ustr, std::size_t width,
if (newlen > width) {
unistring temp(*i);
if (temp.length() > static_cast<std::size_t>(account_abbrev_length)) {
if (temp.length() > account_abbrev_length) {
result << temp.extract(0, account_abbrev_length) << ":";
newlen -= temp.length() - account_abbrev_length;
} else {

View file

@ -65,10 +65,7 @@ class format_t : public noncopyable
{
#define ELEMENT_ALIGN_LEFT 0x01
enum kind_t {
STRING,
EXPR,
};
enum kind_t { STRING, EXPR };
kind_t type;
std::size_t min_width;
@ -89,7 +86,7 @@ class format_t : public noncopyable
friend inline void mark_red(std::ostream& out, const element_t * elem) {
out.setf(std::ios::left);
out.width(0);
out << "\e[31m";
out << "\033[31m";
if (elem->has_flags(ELEMENT_ALIGN_LEFT))
out << std::left;
@ -145,8 +142,9 @@ public:
elem->dump(out);
}
static string truncate(const unistring& str, std::size_t width,
const int account_abbrev_length = -1);
static string truncate(const unistring& str,
const std::size_t width,
const std::size_t account_abbrev_length = 0);
};
#define FMT_PREFIX "fmt_"

View file

@ -92,6 +92,10 @@ inline bool interactive_t::get<bool>(std::size_t index) {
return value_at(index).to_boolean();
}
template <>
inline int interactive_t::get<int>(std::size_t index) {
return value_at(index).to_int();
}
template <>
inline long interactive_t::get<long>(std::size_t index) {
return value_at(index).to_long();
}

View file

@ -142,7 +142,7 @@ void item_t::parse_tags(const char * p, optional<date_t::year_type> current_year
for (char * q = std::strtok(buf.get(), " \t");
q;
q = std::strtok(NULL, " \t")) {
const std::size_t len = std::strlen(q);
const string::size_type len = std::strlen(q);
if (! tag.empty()) {
if (! has_tag(tag))
set_tag(tag, string(p + (q - buf.get())));

View file

@ -110,8 +110,8 @@ void process_option(const string& whence, const string& name, scope_t& scope,
void process_environment(const char ** envp, const string& tag,
scope_t& scope)
{
const char * tag_p = tag.c_str();
std::size_t tag_len = tag.length();
const char * tag_p = tag.c_str();
string::size_type tag_len = tag.length();
for (const char ** p = envp; *p; p++) {
if (! tag_p || std::strncmp(*p, tag_p, tag_len) == 0) {

View file

@ -56,11 +56,11 @@ template <typename T>
class option_t
{
protected:
const char * name;
std::size_t name_len;
const char ch;
bool handled;
optional<string> source;
const char * name;
string::size_type name_len;
const char ch;
bool handled;
optional<string> source;
option_t& operator=(const option_t&);

View file

@ -491,9 +491,10 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags,
if (original_string) {
add_error_context(_("While parsing value expression:"));
std::size_t end_pos =
in.good() ? static_cast<std::size_t>(in.tellg()) : 0;
std::size_t pos = static_cast<std::size_t>(end_pos);
std::streamoff end_pos = 0;
if (in.good())
end_pos = in.tellg();
std::streamoff pos = end_pos;
if (pos > 0)
pos -= lookahead.length;
@ -504,7 +505,9 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags,
DEBUG("parser.error", " token kind = " << int(lookahead.kind));
DEBUG("parser.error", " token length = " << lookahead.length);
add_error_context(line_context(*original_string, pos, end_pos));
add_error_context(line_context(*original_string,
static_cast<string::size_type>(pos),
static_cast<string::size_type>(end_pos)));
}
throw;
}

View file

@ -195,7 +195,8 @@ namespace {
string name = env->reported_account()->fullname();
if (env.has(0) && env.get<long>(0) > 2)
name = format_t::truncate(name, env.get<long>(0) - 2, true);
name = format_t::truncate(name, env.get<long>(0) - 2,
2 /* account_abbrev_length */);
if (env->has_flags(POST_VIRTUAL)) {
if (env->must_balance())

View file

@ -109,9 +109,9 @@ protected:
* - at most, pbSize characters in putback area plus
* - at most, bufSize characters in ordinary read buffer
*/
static const int pbSize = 4; // size of putback area
static const int bufSize = 1024; // size of the data buffer
char buffer[bufSize + pbSize]; // data buffer
static const size_t pbSize = 4; // size of putback area
static const size_t bufSize = 1024; // size of the data buffer
char buffer[bufSize + pbSize]; // data buffer
public:
/* constructor
@ -147,7 +147,7 @@ protected:
* - use number of characters read
* - but at most size of putback area
*/
int numPutback;
size_t numPutback;
numPutback = gptr() - eback();
if (numPutback > pbSize) {
numPutback = pbSize;
@ -160,14 +160,13 @@ protected:
numPutback);
// read at most bufSize new characters
int num;
PyObject *line = PyFile_GetLine(reinterpret_cast<PyObject *>(fo), bufSize);
if (! line || ! PyString_Check(line)) {
// ERROR or EOF
return EOF;
}
num = PyString_Size(line);
Py_ssize_t num = PyString_Size(line);
if (num == 0)
return EOF;

View file

@ -266,7 +266,7 @@ value_t python_interpreter_t::python_command(call_scope_t& args)
std::strcpy(argv[i + 1], arg.c_str());
}
int status = Py_Main(args.size() + 1, argv);
int status = Py_Main(static_cast<int>(args.size()) + 1, argv);
for (std::size_t i = 0; i < args.size() + 1; i++)
delete[] argv[i];

View file

@ -105,6 +105,7 @@ public:
virtual expr_t::ptr_op_t lookup(const string& name);
#if BOOST_VERSION >= 103700
OPTION_(python_interpreter_t, import_, DO_(scope) {
interactive_t args(scope, "s");
@ -114,23 +115,31 @@ public:
python::object sys_dict = module_sys.attr("__dict__");
python::list paths(sys_dict["path"]);
#if BOOST_VERSION >= 103700
paths.insert(0, file.parent_path().string());
#else
paths.insert(0, file.branch_path().string());
#endif
sys_dict["path"] = paths;
#if BOOST_VERSION >= 103700
string name = file.filename();
if (contains(name, ".py"))
parent->import(file.stem());
else
parent->import(name);
#else
parent->import(file.leaf());
#endif
});
#else // BOOST_VERSION >= 103700
OPTION_(python_interpreter_t, import_, DO_(scope) {
interactive_t args(scope, "s");
path file(args.get<string>(0));
python::object module_sys = parent->import("sys");
python::object sys_dict = module_sys.attr("__dict__");
python::list paths(sys_dict["path"]);
paths.insert(0, file.branch_path().string());
sys_dict["path"] = paths;
parent->import(file.leaf());
});
#endif // BOOST_VERSION >= 103700
};
extern shared_ptr<python_interpreter_t> python_session;

View file

@ -211,8 +211,8 @@ value_t report_t::fn_truncated(call_scope_t& scope)
interactive_t args(scope, "v&ll");
return string_value(format_t::truncate
(args.get<string>(0),
args.has(1) && args.get<long>(1) > 0 ? args.get<long>(1) : 0,
args.has(2) ? args.get<long>(2) : -1));
args.has(1) && args.get<int>(1) > 0 ? args.get<int>(1) : 0,
args.has(2) ? args.get<int>(2) : 0));
}
value_t report_t::fn_justify(call_scope_t& scope)
@ -220,8 +220,8 @@ value_t report_t::fn_justify(call_scope_t& scope)
interactive_t args(scope, "vl&lbbs");
std::ostringstream out;
args.value_at(0)
.print(out, args.get<long>(1),
args.has(2) ? args.get<long>(2) : -1,
.print(out, args.get<int>(1),
args.has(2) ? args.get<int>(2) : -1,
args.has(3) ? args.get<bool>(3) : false,
args.has(4) ? args.get<bool>(4) : false,
args.has(5) ? args.get<string>(5) :
@ -275,19 +275,19 @@ value_t report_t::fn_ansify_if(call_scope_t& scope)
if (args.has(1)) {
string color = args.get<string>(1);
std::ostringstream buf;
if (color == "black") buf << "\e[30m";
else if (color == "red") buf << "\e[31m";
else if (color == "green") buf << "\e[32m";
else if (color == "yellow") buf << "\e[33m";
else if (color == "blue") buf << "\e[34m";
else if (color == "magenta") buf << "\e[35m";
else if (color == "cyan") buf << "\e[36m";
else if (color == "white") buf << "\e[37m";
else if (color == "bold") buf << "\e[1m";
else if (color == "underline") buf << "\e[4m";
else if (color == "blink") buf << "\e[5m";
if (color == "black") buf << "\033[30m";
else if (color == "red") buf << "\033[31m";
else if (color == "green") buf << "\033[32m";
else if (color == "yellow") buf << "\033[33m";
else if (color == "blue") buf << "\033[34m";
else if (color == "magenta") buf << "\033[35m";
else if (color == "cyan") buf << "\033[36m";
else if (color == "white") buf << "\033[37m";
else if (color == "bold") buf << "\033[1m";
else if (color == "underline") buf << "\033[4m";
else if (color == "blink") buf << "\033[5m";
buf << args.value_at(0);
buf << "\e[0m";
buf << "\033[0m";
return string_value(buf.str());
} else {
return args.value_at(0);

View file

@ -83,8 +83,8 @@ namespace std {
}
}
typedef std::size_t istream_pos_type;
typedef std::size_t ostream_pos_type;
typedef std::streamoff istream_pos_type;
typedef std::streamoff ostream_pos_type;
#else // ! (defined(__GNUG__) && __GNUG__ < 3)

View file

@ -103,9 +103,9 @@ inline void justify(std::ostream& out,
bool redden = false)
{
if (! right) {
if (redden) out << "\e[31m";
if (redden) out << "\033[31m";
out << str;
if (redden) out << "\e[0m";
if (redden) out << "\033[0m";
}
unistring temp(str);
@ -115,9 +115,9 @@ inline void justify(std::ostream& out,
out << ' ';
if (right) {
if (redden) out << "\e[31m";
if (redden) out << "\033[31m";
out << str;
if (redden) out << "\e[0m";
if (redden) out << "\033[0m";
}
}

View file

@ -402,17 +402,19 @@ string::string(const char * str) : std::string(str) {
string::string(const char * str, const char * end) : std::string(str, end) {
TRACE_CTOR(string, "const char *, const char *");
}
string::string(const string& str, int x) : std::string(str, x) {
TRACE_CTOR(string, "const string&, int");
string::string(const string& str, size_type x) : std::string(str, x) {
TRACE_CTOR(string, "const string&, size_type");
}
string::string(const string& str, int x, int y) : std::string(str, x, y) {
TRACE_CTOR(string, "const string&, int, int");
string::string(const string& str, size_type x, size_type y)
: std::string(str, x, y) {
TRACE_CTOR(string, "const string&, size_type, size_type");
}
string::string(const char * str, int x) : std::string(str, x) {
TRACE_CTOR(string, "const char *, int");
string::string(const char * str, size_type x) : std::string(str, x) {
TRACE_CTOR(string, "const char *, size_type");
}
string::string(const char * str, int x, int y) : std::string(str, x, y) {
TRACE_CTOR(string, "const char *, int, int");
string::string(const char * str, size_type x, size_type y)
: std::string(str, x, y) {
TRACE_CTOR(string, "const char *, size_type, size_type");
}
string::~string() throw() {
TRACE_DTOR(string);

View file

@ -173,10 +173,10 @@ public:
string(size_type len, char x);
string(const char * str);
string(const char * str, const char * end);
string(const string& str, int x);
string(const string& str, int x, int y);
string(const char * str, int x);
string(const char * str, int x, int y);
string(const string& str, size_type x);
string(const string& str, size_type x, size_type y);
string(const char * str, size_type x);
string(const char * str, size_type x, size_type y);
~string() throw();
};

View file

@ -173,6 +173,17 @@ date_t value_t::to_date() const
}
}
int value_t::to_int() const
{
if (is_long()) {
return static_cast<int>(as_long());
} else {
value_t temp(*this);
temp.in_place_cast(INTEGER);
return static_cast<int>(temp.as_long());
}
}
long value_t::to_long() const
{
if (is_long()) {

View file

@ -733,6 +733,7 @@ public:
* exception is thrown.
*/
bool to_boolean() const;
int to_int() const;
long to_long() const;
datetime_t to_datetime() const;
date_t to_date() const;
@ -788,7 +789,7 @@ public:
/**
* Collection-style access methods for SEQUENCE values.
*/
value_t& operator[](const int index) {
value_t& operator[](const std::size_t index) {
VERIFY(! is_null());
if (is_sequence())
return as_sequence_lval()[index];
@ -799,7 +800,7 @@ public:
static value_t null;
return null;
}
const value_t& operator[](const int index) const {
const value_t& operator[](const std::size_t index) const {
VERIFY(! is_null());
if (is_sequence())
return as_sequence()[index];