Skip to content

Commit

Permalink
compiler: Don't allow builtin function values.
Browse files Browse the repository at this point in the history
According to the spec, http://golang.org/ref/spec#Built-in_functions:
"built-in functions do not have standard Go types, so they can only
appear in call expressions; they cannot be used as function values."

Fixes golang/go#11570.

Change-Id: I398d80e2e6f6a8c23c8f3a2c8b2fb07575c35cf3
Reviewed-on: https://go-review.googlesource.com/12543
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
Chris Manghane authored and ianlancetaylor committed Jul 31, 2015
1 parent 9931f2c commit 4c676d9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions go/gogo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,28 @@ Check_types_traverse::variable(Named_object* named_object)
reason.c_str());
var->clear_init();
}
else if (init != NULL
&& init->func_expression() != NULL)
{
Named_object* no = init->func_expression()->named_object();
Function_type* fntype;
if (no->is_function())
fntype = no->func_value()->type();
else if (no->is_function_declaration())
fntype = no->func_declaration_value()->type();
else
go_unreachable();

// Builtin functions cannot be used as function values for variable
// initialization.
if (fntype->is_builtin())
{
error_at(init->location(),
"invalid use of special builtin function %qs; "
"must be called",
no->message_name().c_str());
}
}
else if (!var->is_used()
&& !var->is_global()
&& !var->is_parameter()
Expand Down

0 comments on commit 4c676d9

Please sign in to comment.