From 587bd42530cee75da83979b18bb170302c915034 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 23 Jun 2019 22:10:19 +0000 Subject: compiler: edit error messages to avoid -Wformat-diag warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC recently introduced -Wformat-diag to scrutinize GCC error messages. It reports a number of warnings about gofrontend code, such as: ../../trunk/gcc/go/gofrontend/import.cc: In member function ‘Type* Import::type_for_index(int, const string&, size_t, bool*)’: ../../trunk/gcc/go/gofrontend/import.cc:1129:48: warning: unquoted operator ‘>=’ in format [-Wformat-diag] 1129 | "error in %s at %lu: bad type index %d >= %d", | ^~ ../../trunk/gcc/go/gofrontend/ast-dump.cc: In member function ‘void Ast_dump_context::dump(Gogo*, const char*)’: ../../trunk/gcc/go/gofrontend/ast-dump.cc:203:25: warning: unquoted option name ‘-fgo-dump-ast’ in format [-Wformat-diag] 203 | "cannot open %s:%m, -fgo-dump-ast ignored", dumpname.c_str()); | ^~~~~~~~~~~~~ ../../trunk/gcc/go/gofrontend/expressions.cc: In static member function ‘static Bexpression* Func_expression::get_code_pointer(Gogo*, Named_object*, Location)’: ../../trunk/gcc/go/gofrontend/expressions.cc:1350:29: warning: misspelled term ‘builtin function’ in format; use ‘built-in function’ instead [-Wformat-diag] 1350 | "invalid use of special builtin function %qs; must be called", | ^~~~~~~~~~~~~~~~ ../../trunk/gcc/go/gofrontend/gogo.cc: In member function ‘void Gogo::add_linkname(const string&, bool, const string&, Location)’: ../../trunk/gcc/go/gofrontend/gogo.cc:2527:4: warning: unquoted sequence of 2 consecutive punctuation characters ‘//’ in format [-Wformat-diag] 2527 | ("%s is not a function; " | ~^~~~~~~~~~~~~~~~~~~~~~~~ 2528 | "//go:linkname is only supported for functions"), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This CL edits error messages to avoid these warnings. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/183497 * go.test/test/blank1.go: Update for diagnostic message changes. From-SVN: r272608 --- gcc/go/gofrontend/parse.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'gcc/go/gofrontend/parse.cc') diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index e611c70..52371b2 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -1359,7 +1359,7 @@ Parse::decl(void (Parse::*pfn)(void*, unsigned int), void* varg, { if (pragmas != 0) go_warning_at(this->location(), 0, - "ignoring magic //go:... comment before group"); + "ignoring magic % comment before group"); if (!this->advance_token()->is_op(OPERATOR_RPAREN)) { this->list(pfn, varg, true); @@ -1605,7 +1605,7 @@ Parse::type_spec(void*, unsigned int pragmas) } if (pragmas != 0) go_warning_at(location, 0, - "ignoring magic //go:... comment before type"); + "ignoring magic % comment before type"); } else { @@ -1633,7 +1633,7 @@ Parse::var_spec(void*, unsigned int pragmas) { if (pragmas != 0) go_warning_at(this->location(), 0, - "ignoring magic //go:... comment before var"); + "ignoring magic % comment before var"); // Get the variable names. Typed_identifier_list til; @@ -2383,7 +2383,7 @@ Parse::function_decl(unsigned int pragmas) if (pragma_check[i].decl_ok) continue; go_warning_at(location, 0, - ("ignoring magic //go:%s comment " + ("ignoring magic % comment " "before declaration"), pragma_check[i].name); } @@ -2392,7 +2392,7 @@ Parse::function_decl(unsigned int pragmas) if (pragma_check[i].func_ok) continue; go_warning_at(location, 0, - ("ignoring magic //go:%s comment " + ("ignoring magic % comment " "before function definition"), pragma_check[i].name); } @@ -2401,7 +2401,7 @@ Parse::function_decl(unsigned int pragmas) if (pragma_check[i].method_ok) continue; go_warning_at(location, 0, - ("ignoring magic //go:%s comment " + ("ignoring magic % comment " "before method definition"), pragma_check[i].name); } @@ -2602,7 +2602,7 @@ Parse::operand(bool may_be_sink, bool* is_parenthesized) return Expression::make_sink(location); else { - go_error_at(location, "cannot use _ as value"); + go_error_at(location, "cannot use %<_%> as value"); return Expression::make_error(location); } case Named_object::NAMED_OBJECT_FUNC: @@ -4178,7 +4178,7 @@ Parse::tuple_assignment(Expression_list* lhs, bool may_be_composite_lit, if ((*pe)->is_error_expression()) return; if (op != OPERATOR_EQ && (*pe)->is_sink_expression()) - go_error_at((*pe)->location(), "cannot use _ as value"); + go_error_at((*pe)->location(), "cannot use %<_%> as value"); } for (Expression_list::const_iterator pe = vals->begin(); pe != vals->end(); @@ -5721,7 +5721,7 @@ Parse::package_clause() name = token->identifier(); if (name == "_") { - go_error_at(this->location(), "invalid package name _"); + go_error_at(this->location(), "invalid package name %<_%>"); name = Gogo::erroneous_name(); } this->advance_token(); @@ -5752,7 +5752,7 @@ Parse::import_spec(void*, unsigned int pragmas) { if (pragmas != 0) go_warning_at(this->location(), 0, - "ignoring magic //go:... comment before import"); + "ignoring magic % comment before import"); const Token* token = this->peek_token(); Location location = token->location(); @@ -5876,7 +5876,7 @@ Parse::verify_not_sink(Expression* expr) { if (expr->is_sink_expression()) { - go_error_at(expr->location(), "cannot use _ as value"); + go_error_at(expr->location(), "cannot use %<_%> as value"); expr = Expression::make_error(expr->location()); } -- cgit v1.1