public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 59729
@ 2015-04-28 22:45 Paolo Carlini
  2015-04-28 23:01 ` Paolo Carlini
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2015-04-28 22:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 166 bytes --]

Hi,

apparently we aren't implementing the bits of DR 1732 [C++14] about 
range-based for declarations. Tested x86_64-linux.

Thanks,
Paolo.

///////////////////////

[-- Attachment #2: CL_59729 --]
[-- Type: text/plain, Size: 359 bytes --]

/cp
2015-04-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59729, DR 1732
	* parser.c (cp_parser_for_init_statement): Do not allow type
	definitions in range-based for loop declarations.

/testsuite
2015-04-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/59729, DR 1732
	* g++.dg/cpp0x/range-for30.C: New.
	* g++.dg/cpp0x/range-for8.C: Update.

[-- Attachment #3: patch_59729 --]
[-- Type: text/plain, Size: 2588 bytes --]

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 222548)
+++ cp/parser.c	(working copy)
@@ -10897,6 +10897,7 @@ cp_parser_for_init_statement (cp_parser* parser, t
     {
       bool is_range_for = false;
       bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p;
+      const char *saved_message = parser->type_definition_forbidden_message;
 
       if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
 	  && cp_lexer_nth_token_is (parser->lexer, 2, CPP_COLON))
@@ -10916,6 +10917,9 @@ cp_parser_for_init_statement (cp_parser* parser, t
 
       /* A colon is used in range-based for.  */
       parser->colon_corrects_to_scope_p = false;
+      parser->type_definition_forbidden_message
+	= G_("types may not be defined in a range-based %<for%> loop "
+	     "declaration");
 
       /* We're going to speculatively look for a declaration, falling back
 	 to an expression, if necessary.  */
@@ -10924,6 +10928,8 @@ cp_parser_for_init_statement (cp_parser* parser, t
       cp_parser_simple_declaration (parser,
 				    /*function_definition_allowed_p=*/false,
 				    decl);
+
+      parser->type_definition_forbidden_message = saved_message;
       parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p;
       if (cp_lexer_next_token_is (parser->lexer, CPP_COLON))
 	{
Index: testsuite/g++.dg/cpp0x/range-for30.C
===================================================================
--- testsuite/g++.dg/cpp0x/range-for30.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/range-for30.C	(working copy)
@@ -0,0 +1,12 @@
+// PR c++/59729, DR 1732
+// { dg-require-effective-target c++11 }
+
+struct S {
+  template <typename T>
+  operator T() { return T(); }
+};
+
+int main() {
+  S s[1];
+  for (struct T { } t : s) { }  // { dg-error "types may not be defined" }
+}
Index: testsuite/g++.dg/cpp0x/range-for8.C
===================================================================
--- testsuite/g++.dg/cpp0x/range-for8.C	(revision 222548)
+++ testsuite/g++.dg/cpp0x/range-for8.C	(working copy)
@@ -1,5 +1,5 @@
 // Test for range-based for loop when the declarator declares
-// a new type
+// a new type (rejected per DR 1732)
 
 // { dg-do compile { target c++11 } }
 
@@ -7,9 +7,9 @@
 
 void test()
 {
-    for (struct S { } *x : { (S*)0, (S*)0 } )
+    for (struct S { } *x : { (S*)0, (S*)0 } ) // { dg-error "types may not be defined" }
         ;
 
-    for (struct S { } x : { S(), S() } )
+    for (struct S { } x : { S(), S() } ) // { dg-error "types may not be defined" }
         ;
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ Patch] PR 59729
  2015-04-28 22:45 [C++ Patch] PR 59729 Paolo Carlini
@ 2015-04-28 23:01 ` Paolo Carlini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Carlini @ 2015-04-28 23:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

.. nope, sorry, what I have doesn't work for eg:

     for (class C {};;)

Paolo.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-28 22:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-28 22:45 [C++ Patch] PR 59729 Paolo Carlini
2015-04-28 23:01 ` Paolo Carlini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).