PR c++/79566 - elaborated-type-specifier in range for
authorJason Merrill <jason@redhat.com>
Mon, 20 Feb 2017 06:05:54 +0000 (01:05 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 20 Feb 2017 06:05:54 +0000 (01:05 -0500)
* parser.c (cp_parser_simple_declaration): Fix check for type
definition.

From-SVN: r245591

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/range-for34.C [new file with mode: 0644]

index ceef9db73c813c2062cee329f0609868f68427b4..8ff836e28d08ee7c1243d8d726da8d754d431160 100644 (file)
@@ -1,5 +1,9 @@
 2017-02-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/79566 - elaborated-type-specifier in range for
+       * parser.c (cp_parser_simple_declaration): Fix check for type
+       definition.
+
        PR c++/79400 - confusing suggestion of 'noexcept'
        * parser.c (cp_parser_exception_specification_opt): Remove
        suggestion for deprecated dynamic exception-specification.
index 72597f3e9f2e86e2c4cf2671e47ef9820a4f3057..0146596d1545a890e2b4ebfe2e20257c61c2a36d 100644 (file)
@@ -12883,7 +12883,7 @@ cp_parser_simple_declaration (cp_parser* parser,
        break;
       else if (maybe_range_for_decl)
        {
-         if (declares_class_or_enum && token->type == CPP_COLON)
+         if ((declares_class_or_enum & 2) && token->type == CPP_COLON)
            permerror (decl_specifiers.locations[ds_type_spec],
                       "types may not be defined in a for-range-declaration");
          break;
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for34.C b/gcc/testsuite/g++.dg/cpp0x/range-for34.C
new file mode 100644 (file)
index 0000000..2041848
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/79566
+// { dg-do compile { target c++11 } }
+
+struct X {
+  struct Y { };
+
+  Y* begin();
+  Y* end();
+};
+
+void f()
+{
+  X x;
+  for (struct X::Y& y : x)
+    ;
+}