On Thu, 2018-07-05 at 04:58 +0000, 冠人 王 via gcc wrote: > In the function emit_side_effect_warnings, I find its inputs are > "location_t loc" and "tree expr". > And, there is a function warn_if_unused_value called by > emit_side_effect_warnings: > emit_side_effect_warnings(location_t loc, tree expr){ ... > else > warn_if_unused_value(expr,loc) > } > > To call warn_if_unused_value, we use location_t loc and tree expr as > inputs > In the function warn_if_unused_value, I find its inputs are > "location_t loc" and "const_tree expr" > warn_if_unused_value(const_tree exp, location_t locus){ ... > } > I am confused about the difference between "tree expr" and > "const_tree expr" since > if I modify the"const_tree" to "tree", I make failed.
The pertinent typedefs are in gcc/coretypes.h tree is defined via: typedef union tree_node *tree; i.e. "tree" is a "union tree_node *". const_tree is almost the same: typedef const union tree_node *const_tree; i.e. "const_tree" is a "const union tree_node *". Both are pointers to tree_node union, but const_tree is a pointer to a const union i.e. it promises not to write to the node. You didn't show us the error message, so I can only guess the problem, but my guess is that by changing it from "const_tree" to "tree", the function is no longer promising not to write to the node, and thus violating constness of something that calls that function. > Besides this, I try to use debug_tree function to dump the > imformation of the node. > I am successful when I use it in the function > emit_side_effect_warnings but > not in the function warn_if_unused_value I see that debug_tree takes a "tree", rather than a "const_tree". I'm guessing that that's a bug, and ought to be fixed. You can probably work around it for now by casting the const_tree back to a tree: debug_tree ((const_tree)exp); or similar. Hope this is helpful; good luck. Dave