This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++0x] Range-based for statements and ADL


On 03/28/2011 08:28 PM, Rodrigo Rivas wrote:
A few comments:
1. I'm not sure about what should happen if the begin/end found in class
scope are not ordinary functions.

Whatever range.begin() would mean if written explicitly.


My guess is that if it is a function
(static or non-static) it is called normally, and if it is a member
variable it is searched for an operator()(). If it is a type it should
fail.

Yes, because we can't use . syntax to name type members.


+ error ("range-based-for expression must be of a complete type");

I like your "range-based %<for%>" suggestion. I'd also say "must have complete type".


  static void
  cp_parser_perform_range_for_lookup (tree range, tree *begin, tree *end)

This function needs a comment.


+  *end = finish_class_member_access_expr(range, *end,
+                                        false, tf_none);
+
+  VEC(tree,gc) *vec;
+  vec = make_tree_vector ();

The declaration of vec needs to move to the top of the function.


+  id_begin = get_identifier ("begin");
+  *begin = build_qualified_name (/*type=*/NULL_TREE,
+                                    TREE_TYPE (range),
+                                    id_begin,
+                                    /*template_p=*/false);
+  *begin = finish_class_member_access_expr(range, *begin,
+                                              false, tf_none);
+
+  id_end = get_identifier ("end");
+  *end = build_qualified_name (/*type=*/NULL_TREE,
+                              TREE_TYPE (range),
+                              id_end,
+                              /*template_p=*/false);
+  *end = finish_class_member_access_expr(range, *end,
+                                        false, tf_none);

Don't call build_qualified_name here; the standard doesn't say range.T::begin(), just range.begin().


Also, we can't just call finish_class_member_access_expr here because it returns error_mark_node for any error condition, so we can't tell the difference between a lookup that didn't find anything (in which case we want to fall back to ADL) and an access violation (in which case we want to give an error).

We need to do the lookup directly first, and then do finish_class_member_access_expr after we've decided to use the members.

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]