------- Comment #4 from krebbel at gcc dot gnu dot org 2007-11-19 13:32 ------- The problem occurs since this patch has removed the promotion of result types of a function decl: http://gcc.gnu.org/ml/gcc-patches/2007-07/msg00424.html With this patch the enum Status return type of getStatus is not promoted to int anymore and the enum type tree node is passed to the back end hook. Unfortunately enum types defined within a template declaration are not fully processed when they are defined. According to a comment in finish_enum the full processing is postponed to the point when the template gets instantiated.
The back end hook is not called with the error mark node as I wrote in my last comment. The error mark node is created when our back end invokes promote_mode with the not fully processed enum type node and VOIDmode as mode parameter. Why is the back end involved at all? The example doesn't produce any code so why the back end has to bother in which register a value will be returned?! A comment in start_preparsed_function says that this is necessary to have CFUN set up - mmh. I think the bug is that a back end hook is invoked with a tree type node before the front end specific type promotions have been applied. So either we don't involve the back end at all or we promote enums to ints as it was done before. If I understand this correctly the whole layout of the function type is anyway re-done when the template gets instantiated. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34081