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
-6bb63a21434b3360dbe7e4bd34889734f361d434
+1232eef628227ef855c5fa6d94b31778b2e74a85
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
if (out.fail())
{
go_error_at(Linemap::unknown_location(),
- "cannot open %s:%m, -fgo-dump-ast ignored", dumpname.c_str());
+ "cannot open %s:%m; %<-fgo-dump-ast%> ignored",
+ dumpname.c_str());
return;
}
if (fntype->is_builtin())
{
go_error_at(loc,
- "invalid use of special builtin function %qs; must be called",
+ ("invalid use of special built-in function %qs; "
+ "must be called"),
no->message_name().c_str());
return gogo->backend()->error_expression();
}
if (no->func_declaration_value()->type()->is_builtin())
{
go_error_at(this->location(),
- ("invalid use of special builtin function %qs; "
+ ("invalid use of special built-in function %qs; "
"must be called"),
no->message_name().c_str());
return gogo->backend()->error_expression();
if (!type->in_heap())
go_error_at(first_arg->location(),
- "can't make slice of go:notinheap type");
+ "cannot make slice of go:notinheap type");
bool is_slice = false;
bool is_map = false;
{
if (this->code_ == BUILTIN_PRINT)
go_warning_at(this->location(), 0,
- "no arguments for builtin function %<%s%>",
+ "no arguments for built-in function %<%s%>",
(this->code_ == BUILTIN_PRINT
? "print"
: "println"));
Type* element_type = slice_type->array_type()->element_type();
if (!element_type->in_heap())
go_error_at(args->front()->location(),
- "can't append to slice of go:notinheap type");
+ "cannot append to slice of go:notinheap type");
if (this->is_varargs())
{
if (!args->back()->type()->is_slice_type()
Allocation_expression::do_check_types(Gogo*)
{
if (!this->type_->in_heap())
- go_error_at(this->location(), "can't heap allocate go:notinheap type");
+ go_error_at(this->location(), "cannot heap allocate go:notinheap type");
}
// Make a copy of an allocation expression.
if (issue_error)
{
go_error_at(location,
- "floating point constant truncated to integer");
+ "floating-point constant truncated to integer");
this->set_invalid();
}
return false;
if (issue_error)
{
this->set_invalid();
- go_error_at(location, "complex constant truncated to float");
+ go_error_at(location,
+ "complex constant truncated to floating-point");
}
return false;
}
if (!ret && issue_error)
{
- go_error_at(location, "floating point constant overflow");
+ go_error_at(location, "floating-point constant overflow");
this->set_invalid();
}
p != linknames->end();
++p)
go_error_at(p->second.loc,
- ("//go:linkname only allowed in Go files that "
+ ("%<//go:linkname%> only allowed in Go files that "
"import \"unsafe\""));
}
all_linknames.insert(linknames->begin(), linknames->end());
if (package->pkgpath() == this->pkgpath())
go_error_at(location,
("imported package uses same package path as package "
- "being compiled (see -fgo-pkgpath option)"));
+ "being compiled (see %<-fgo-pkgpath%> option)"));
this->imports_.insert(std::make_pair(filename, package));
}
else
go_error_at(loc,
("%s is not a function; "
- "//go:linkname is only supported for functions"),
+ "%<//go:linkname%> is only supported for functions"),
go_name.c_str());
}
if (fntype->is_builtin())
{
go_error_at(init->location(),
- "invalid use of special builtin function %qs; "
+ "invalid use of special built-in function %qs; "
"must be called",
no->message_name().c_str());
}
++p)
go_error_at((*p)->location(),
("invalid receiver type "
- "(receiver must be a named type"));
+ "(receiver must be a named type)"));
return;
}
}
char* buf = new char[sizeof(hdr.ar_size) + 1];
memcpy(buf, hdr.ar_size, sizeof(hdr.ar_size));
go_error_at(this->location_,
- ("%s: malformed ar_size in entry header at %ld"
+ ("%s: malformed size in entry header at %ld"
" (expected decimal, got %s)"),
this->filename_.c_str(), static_cast<long>(off), buf);
delete[] buf;
char* buf = new char[sizeof(hdr.ar_namlen) + 1];
memcpy(buf, hdr.ar_namlen, sizeof(hdr.ar_namlen));
go_error_at(this->location_,
- ("%s: malformed ar_namlen in entry header at %ld"
+ ("%s: malformed name length in entry header at %ld"
" (expected decimal, got %s)"),
this->filename_.c_str(), static_cast<long>(off), buf);
delete[] buf;
char* buf = new char[sizeof(hdr.ar_nxtmem) + 1];
memcpy(buf, hdr.ar_nxtmem, sizeof(hdr.ar_nxtmem));
go_error_at(this->location_,
- ("%s: malformed ar_nxtmem in entry header at %ld"
+ ("%s: malformed next member offset in entry header at %ld"
" (expected decimal, got %s)"),
this->filename_.c_str(), static_cast<long>(off), buf);
delete[] buf;
int nfd = open(filename.c_str(), O_RDONLY | O_BINARY);
if (nfd < 0)
{
- go_error_at(this->location_, "%s: can't open nested archive %s",
+ go_error_at(this->location_, "%s: cannot open nested archive %s",
this->filename_.c_str(), filename.c_str());
return false;
}
{
if (!stream->saw_error())
go_error_at(this->location_,
- "error in import data at %d: expected %< %> or %<>%>'",
+ "error in import data at %d: expected %< %> or %<>%>",
stream->pos());
stream->set_saw_error();
stream->advance(1);
if (static_cast<size_t>(index) >= this->type_offsets_.size())
{
go_error_at(this->location_,
- "error in %s at %lu: bad type index %d >= %d",
+ "error in %s at %lu: bad type index %d, max %d",
input_name.c_str(),
static_cast<unsigned long>(input_offset),
index, static_cast<int>(this->type_offsets_.size()));
}
}
if (go_name.empty() || ext_name.empty())
- go_error_at(loc, "usage: //go:linkname localname linkname");
+ go_error_at(loc, "usage: %<//go:linkname%> localname linkname");
else
{
if (this->linknames_ == NULL)
{
if (pragmas != 0)
go_warning_at(this->location(), 0,
- "ignoring magic //go:... comment before group");
+ "ignoring magic %<//go:...%> comment before group");
if (!this->advance_token()->is_op(OPERATOR_RPAREN))
{
this->list(pfn, varg, true);
}
if (pragmas != 0)
go_warning_at(location, 0,
- "ignoring magic //go:... comment before type");
+ "ignoring magic %<//go:...%> comment before type");
}
else
{
{
if (pragmas != 0)
go_warning_at(this->location(), 0,
- "ignoring magic //go:... comment before var");
+ "ignoring magic %<//go:...%> comment before var");
// Get the variable names.
Typed_identifier_list til;
if (pragma_check[i].decl_ok)
continue;
go_warning_at(location, 0,
- ("ignoring magic //go:%s comment "
+ ("ignoring magic %<//go:%s%> comment "
"before declaration"),
pragma_check[i].name);
}
if (pragma_check[i].func_ok)
continue;
go_warning_at(location, 0,
- ("ignoring magic //go:%s comment "
+ ("ignoring magic %<//go:%s%> comment "
"before function definition"),
pragma_check[i].name);
}
if (pragma_check[i].method_ok)
continue;
go_warning_at(location, 0,
- ("ignoring magic //go:%s comment "
+ ("ignoring magic %<//go:%s%> comment "
"before method definition"),
pragma_check[i].name);
}
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:
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();
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();
{
if (pragmas != 0)
go_warning_at(this->location(), 0,
- "ignoring magic //go:... comment before import");
+ "ignoring magic %<//go:...%> comment before import");
const Token* token = this->peek_token();
Location location = token->location();
{
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());
}
{
if (!ifb->saw_error())
go_error_at(ifb->location(),
- "import error: no newline after { at %lu",
+ "import error: no newline after %<{%> at %lu",
static_cast<unsigned long>(ifb->off()));
ifb->set_saw_error();
return NULL;
+2019-06-23 Ian Lance Taylor <iant@golang.org>
+
+ * go.test/test/blank1.go: Update for diagnostic message changes.
+
2019-06-23 Iain Sandoe <iain@sandoe.co.uk>
* gcc.target/powerpc/builtins-2.c: Require VSX hardware support.
// Test that incorrect uses of the blank identifer are caught.
// Does not compile.
-package _ // ERROR "invalid package name _"
+package _ // ERROR "invalid package name"
var t struct {
_ int
}
func main() {
- _() // ERROR "cannot use _ as value"
- x := _+1 // ERROR "cannot use _ as value"
+ _() // ERROR "cannot use .* as value"
+ x := _+1 // ERROR "cannot use .* as value"
_ = x
_ = t._ // ERROR "cannot refer to blank field|invalid use of"