]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Implement P0962
authorVille Voutilainen <ville.voutilainen@gmail.com>
Thu, 29 Mar 2018 14:10:22 +0000 (17:10 +0300)
committerVille Voutilainen <ville@gcc.gnu.org>
Thu, 29 Mar 2018 14:10:22 +0000 (17:10 +0300)
Backport from mainline
2018-03-23  Ville Voutilainen  <ville.voutilainen@gmail.com>

Implement P0962
        * parser.c (cp_parser_perform_range_for_lookup): Change
        the condition for deciding whether to use members.

From-SVN: r258956

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/range-for13.C

index 6e1648fb4a94c0a89b3de205f2fb89df598a0073..220130b1ff44de4ed56f890675c656bc956f1eeb 100644 (file)
@@ -1,3 +1,12 @@
+2018-03-29  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Backport from mainline
+       2018-03-23  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Implement P0962
+       * parser.c (cp_parser_perform_range_for_lookup): Change
+       the condition for deciding whether to use members.
+
 2018-03-23  Jason Merrill  <jason@redhat.com>
 
        PR c++/78489 - Substitution in wrong order
index 3a056e4135b1cb4615adaed3cf61d89cff66e70c..89be90a783cbe7e30d28a720922755a7181440dc 100644 (file)
@@ -11459,7 +11459,7 @@ cp_parser_perform_range_for_lookup (tree range, tree *begin, tree *end)
                                  /*protect=*/2, /*want_type=*/false,
                                  tf_warning_or_error);
 
-      if (member_begin != NULL_TREE || member_end != NULL_TREE)
+      if (member_begin != NULL_TREE && member_end != NULL_TREE)
        {
          /* Use the member functions.  */
          if (member_begin != NULL_TREE)
index 100f531f7606a015c31ba96fa3e9561a58bd18c0..7babd713cfbbbb1411b0db9bff1a0f0464655f02 100644 (file)
@@ -3,16 +3,6 @@
 
 // { dg-do compile { target c++11 } }
 
-//These should not be used
-template<typename T> int *begin(T &t)
-{
-    T::fail;
-}
-template<typename T> int *end(T &t)
-{
-    T::fail;
-}
-
 struct container1
 {
     int *begin();
@@ -87,10 +77,37 @@ struct container10
     static function end;
 };
 
+namespace N
+{
+template<typename T> int *begin(T &t)
+{
+    return 0;
+}
+template<typename T> int *end(T &t)
+{
+    return 0;
+}
+struct container11
+{
+    int *begin();
+    //no end
+};
+
+struct container12
+{
+    int *end();
+    //no begin
+};
+
+struct container13
+{
+};
+}
+
 void test1()
 {
-  for (int x : container1()); // { dg-error "member but not" }
-  for (int x : container2()); // { dg-error "member but not" }
+  for (int x : container1()); // { dg-error "'begin' was not declared|'end' was not declared" }
+  for (int x : container2()); // { dg-error "'begin' was not declared|'end' was not declared" }
   for (int x : container3()); // { dg-error "within this context" }
   for (int x : container4()); // { dg-error "cannot be used as a function" }
   for (int x : container5()); // { dg-error "invalid use of" }
@@ -99,4 +116,7 @@ void test1()
   for (int x : container8());
   for (int x : container9()); // { dg-error "within this context" }
   for (int x : container10());
+  for (int x : N::container11());
+  for (int x : N::container12());
+  for (int x : N::container13());
 }