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]

[C++ PATCH] Disallow type specifiers among lambda-declarator decl-specifier-seq (PR c++/86550)


Hi!

The standard says:
"In the decl-specifier-seq of the lambda-declarator, each decl-specifier shall
either be mutable or constexpr."
and the C++ FE has CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR flag for that.
But as implemented, it is actually
CP_PARSER_FLAGS_ONLY_TYPE_OR_MUTABLE_OR_CONSTEXPR
as it allows mutable, constexpr and type specifiers.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2018-07-17  Jakub Jelinek  <jakub@redhat.com>

	PR c++/86550
	* parser.c (cp_parser_decl_specifier_seq): Don't parse a type specifier
	if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR.

	* g++.dg/cpp0x/lambda/lambda-86550.C: New test.

--- gcc/cp/parser.c.jj	2018-07-16 09:42:24.534984748 +0200
+++ gcc/cp/parser.c	2018-07-17 16:22:03.208497718 +0200
@@ -13738,7 +13738,9 @@ cp_parser_decl_specifier_seq (cp_parser*
 
       /* If we don't have a DECL_SPEC yet, then we must be looking at
 	 a type-specifier.  */
-      if (!found_decl_spec && !constructor_p)
+      if (!found_decl_spec
+	  && !constructor_p
+	  && !(flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR))
 	{
 	  int decl_spec_declares_class_or_enum;
 	  bool is_cv_qualifier;
--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-86550.C.jj	2018-07-17 16:24:09.966665292 +0200
+++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-86550.C	2018-07-17 16:29:22.558078546 +0200
@@ -0,0 +1,9 @@
+// PR c++/86550
+// { dg-do compile { target c++11 } }
+
+void
+foo ()
+{
+  auto a = []() bool {};			// { dg-error "expected" }
+  auto b = []() bool bool bool bool int {};	// { dg-error "expected" }
+}

	Jakub


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