]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Don't offer suggestions for compiler-generated variables (PR c++/85515)
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 27 Apr 2018 18:39:18 +0000 (18:39 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Fri, 27 Apr 2018 18:39:18 +0000 (18:39 +0000)
gcc/cp/ChangeLog:
PR c++/85515
* name-lookup.c (consider_binding_level): Skip compiler-generated
variables.
* search.c (lookup_field_fuzzy_info::fuzzy_lookup_field): Flatten
nested if statements into a series of rejection tests.  Reject
lambda-ignored entities as suggestions.

gcc/testsuite/ChangeLog:
PR c++/85515
* g++.dg/pr85515-1.C: New test.
* g++.dg/pr85515-2.C: New test.

From-SVN: r259720

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/cp/search.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr85515-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/pr85515-2.C [new file with mode: 0644]

index 2dbc67501c5c131ac7aecce62ab0824e7559542b..d8e7089af859d94313acb5a602844f21e5040f23 100644 (file)
@@ -1,3 +1,12 @@
+2018-04-27  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/85515
+       * name-lookup.c (consider_binding_level): Skip compiler-generated
+       variables.
+       * search.c (lookup_field_fuzzy_info::fuzzy_lookup_field): Flatten
+       nested if statements into a series of rejection tests.  Reject
+       lambda-ignored entities as suggestions.
+
 2018-04-27  Jason Merrill  <jason@redhat.com>
 
        * cvt.c (cp_fold_convert): Use convert_ptrmem.
index c1f7cf5817bc8fd255a9bad365ea34cf442f8e67..2af2462825ca3b9117aa71f1ea37aeb82c4cf400 100644 (file)
@@ -5860,6 +5860,12 @@ consider_binding_level (tree name, best_match <tree, const char *> &bm,
          && DECL_ANTICIPATED (d))
        continue;
 
+      /* Skip compiler-generated variables (e.g. __for_begin/__for_end
+        within range for).  */
+      if (TREE_CODE (d) == VAR_DECL
+         && DECL_ARTIFICIAL (d))
+       continue;
+
       tree suggestion = DECL_NAME (d);
       if (!suggestion)
        continue;
index bfeaf2cc81968ca2e461ad7ce00de155a51bbad9..22c0492f535c1922808ecc7bd2ac02142c6d5915 100644 (file)
@@ -1224,9 +1224,16 @@ lookup_field_fuzzy_info::fuzzy_lookup_field (tree type)
 
   for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
     {
-      if (!m_want_type_p || DECL_DECLARES_TYPE_P (field))
-       if (DECL_NAME (field))
-         m_candidates.safe_push (DECL_NAME (field));
+      if (m_want_type_p && !DECL_DECLARES_TYPE_P (field))
+       continue;
+
+      if (!DECL_NAME (field))
+       continue;
+
+      if (is_lambda_ignored_entity (field))
+       continue;
+
+      m_candidates.safe_push (DECL_NAME (field));
     }
 }
 
index a20bfd0c1dc17831a994c3afda10766fed39046f..ce5eabadb5749924621cd535eae5f66980faee33 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-27  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/85515
+       * g++.dg/pr85515-1.C: New test.
+       * g++.dg/pr85515-2.C: New test.
+
 2018-04-27  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/84691
diff --git a/gcc/testsuite/g++.dg/pr85515-1.C b/gcc/testsuite/g++.dg/pr85515-1.C
new file mode 100644 (file)
index 0000000..0e27a9d
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-require-effective-target c++14 }
+
+void test_1 ()
+{
+  auto lambda = [val = 2](){};
+  lambda.val; // { dg-bogus "did you mean" }
+  // { dg-error "has no member named 'val'" "" { target *-*-* } .-1 }
+}
+
+int test_2 ()
+{
+  auto lambda = [val = 2](){ return val; };
+
+  // TODO: should we issue an error for the following assignment?
+  lambda.__val = 4;
+
+  return lambda();
+}
diff --git a/gcc/testsuite/g++.dg/pr85515-2.C b/gcc/testsuite/g++.dg/pr85515-2.C
new file mode 100644 (file)
index 0000000..621ddb8
--- /dev/null
@@ -0,0 +1,22 @@
+// { dg-require-effective-target c++11 }
+
+void test_1 ()
+{
+  int arr[] = {1, 2, 3, 4, 5};
+  for (const auto v: arr) {
+    _forbegin; // { dg-bogus "suggested alternative" }
+    // { dg-error "'_forbegin' was not declared in this scope" "" { target *-*-*} .-1 }
+  }
+}
+
+int test_2 ()
+{
+  int arr[] = {1, 2, 3, 4, 5};
+  int sum = 0;
+  for (const auto v: arr) {
+    sum += v;
+    // TODO: should we issue an error for the following assignment?
+    __for_begin = __for_end;
+  }
+  return sum;
+}