[C++-11] User defined literals

Jason Merrill jason@redhat.com
Wed Oct 5 21:24:00 GMT 2011


On 10/05/2011 11:55 AM, Ed Smith-Rowland wrote:
> +         int num_parms = TREE_VEC_LENGTH (parameter_list);
> +         if (num_parms != 1)
> +           ok = false;
> +         else
> +           {
> +             tree parm_list = TREE_VEC_ELT (parameter_list, 0);
> +             tree parm = INNERMOST_TEMPLATE_PARMS (parm_list);

This is backwards; you want to do INNERMOST_TEMPLATE_PARMS before 
looking at the number of parms or pulling out the one at index 0.

> +struct GTY(()) tree_userdef_literal {
> +  struct tree_common common;

I think you can use tree_base instead of tree_common here, since you 
aren't using TREE_TYPE or TREE_CHAIN.

> One thing doesn't work.  Earlier I had said that friend declarations failed.  Not true.  What fails is defining the function body in the class definition.  The function is simply not recorded.  I'm trying to track this down but pointers would be helpful.  If I write the function body outside the class definition friend works perfectly.

> About friends.  The lookup for user-defined literal operators isn't ADL.  They are a lot like normal functions because of the suffix-id as opposed to operator<< in this regard.  Thus a friend literal operator should be accessible both as an explicit operator call and via a literal.  Both are tested and except as noted above about inline defs the tests pass.

A function that is only declared in a friend declaration can only be 
found by ADL, so that doesn't sound like a failure to me; it sounds like 
it's working the way it should.  However, if you declare the function 
earlier and then define it in the friend declaration it ought to work.

Jason



More information about the Gcc-patches mailing list