@@ -5863,6 +5863,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;
@@ -1227,9 +1227,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));
}
}
new file mode 100644
@@ -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();
+}
new file mode 100644
@@ -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;
+}