------- Comment #1 from dodji at gcc dot gnu dot org 2010-03-11 16:17 ------- Created an attachment (id=20085) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20085&action=view) Draft patch
Please find below a copy/paste of the introductory comment of the attached patch. Basically the value of DW_AT_default_value -- as explained by the DWARF4 draft specification -- is either a constant if the default argument of the function is a constant, or a reference to a DIE if the value of the default argument is a language construct like a variable. I believe there are cases however where it's hard (impossible yet?) to represent the value of DW_AT_default_value. For instance, when the default argument of a function F is an arbitrary expression that yields temporaries. In that case, the default argument expression must be evaluated in the context of the caller of F. Just taking in account the default argument expression in the context of the F declaration is not enough. I am not sure we can represent that in DWARF today, can we? So this patch is limited to the simple cases were the default argument is either a constant or a variable that does not involve any temporary. When a default argument expression involves some temporaries, no debug info is generated for it. For a class, it appears that we were calling finish_struct right before parsing default arguments of the member functions. finish_struct does the layout of the class. So we do the layout of the class before parsing the defaut arguments because they can refer to parts of the struct that need to be constructed before. The problem is finish_struct also generates debug info for the class. That means, when we generate debug info for the struct, we don't have any information ready about the default arguments. The patch allows finish_struct to not emit debug info systematically. We can then keep calling finish_struct "early" and emit debug info only after we parsed the default arguments. We do something similar at class template instantiation time. We emit debug info only after the template arguments are substituted into the default arguments expressions. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42959