In Go it is possible to have an initialization loop in a constant initializer, if the initializer is a function pointer. This patch adds that check to the gccgo frontend. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r e19e56d17d8c go/gogo-tree.cc --- a/go/gogo-tree.cc Fri Feb 17 07:42:24 2012 -0800 +++ b/go/gogo-tree.cc Fri Feb 17 11:02:24 2012 -0800 @@ -834,8 +834,15 @@ else if (init == NULL_TREE) ; else if (TREE_CONSTANT(init)) - this->backend()->global_variable_set_init(var, - tree_to_expr(init)); + { + if (expression_requires(no->var_value()->init(), NULL, no)) + error_at(no->location(), + "initialization expression for %qs depends " + "upon itself", + no->message_name().c_str()); + this->backend()->global_variable_set_init(var, + tree_to_expr(init)); + } else if (is_sink) var_init_tree = init; else