diff mbox

[C++] sizeof... and parentheses

Message ID alpine.DEB.2.02.1204201459050.2583@laptop-mg.saclay.inria.fr
State New
Headers show

Commit Message

Marc Glisse April 20, 2012, 1:13 p.m. UTC
Hello,

here is a patch that requires parentheses around the argument of 
sizeof.... I am not sure what variadic76.C tests, so I put 2 lines, with 
parentheses in different places.

bootstrapped and regression tested (make -k check, compared to an 
unpatched version).

Note that I can't commit.


gcc/cp/ChangeLog
2012-04-20  Marc Glisse  <marc.glisse@inria.fr>

 	PR c++/51314
 	* parser.c (cp_parser_sizeof_operand): Require parentheses for
 	sizeof...


gcc/testsuite/ChangeLog
2012-04-20  Marc Glisse  <marc.glisse@inria.fr>

 	PR c++/51314
 	* g++.dg/cpp0x/vt-51314.C: New test.
 	* g++.dg/cpp0x/variadic76.C: Fix.

Comments

Marc Glisse April 30, 2012, 3:14 p.m. UTC | #1
Ping ?

http://gcc.gnu.org/ml/gcc-patches/2012-04/txt00094.txt

Adding Gabriel in Cc: in case this falls in the diagnostic category.

On Fri, 20 Apr 2012, Marc Glisse wrote:

> Hello,
>
> here is a patch that requires parentheses around the argument of sizeof.... I 
> am not sure what variadic76.C tests, so I put 2 lines, with parentheses in 
> different places.
>
> bootstrapped and regression tested (make -k check, compared to an unpatched 
> version).
>
> Note that I can't commit.
>
>
> gcc/cp/ChangeLog
> 2012-04-20  Marc Glisse  <marc.glisse@inria.fr>
>
> 	PR c++/51314
> 	* parser.c (cp_parser_sizeof_operand): Require parentheses for
> 	sizeof...
>
>
> gcc/testsuite/ChangeLog
> 2012-04-20  Marc Glisse  <marc.glisse@inria.fr>
>
> 	PR c++/51314
> 	* g++.dg/cpp0x/vt-51314.C: New test.
> 	* g++.dg/cpp0x/variadic76.C: Fix.
diff mbox

Patch

Index: testsuite/g++.dg/cpp0x/variadic76.C
===================================================================
--- testsuite/g++.dg/cpp0x/variadic76.C	(revision 186616)
+++ testsuite/g++.dg/cpp0x/variadic76.C	(working copy)
@@ -2,11 +2,12 @@ 
 // { dg-do compile }
 // { dg-options "-std=gnu++0x" }
 
 template<int... N> int foo ()
 {
-  return sizeof... N ();	// { dg-error "cannot be used as a function" }
+  return sizeof... (N ());	// { dg-error "cannot be used as a function" }
+  return sizeof... (N) ();	// { dg-error "cannot be used as a function" }
 }
 
 int bar ()
 {
   return foo<0> ();
Index: testsuite/g++.dg/cpp0x/vt-51314.C
===================================================================
--- testsuite/g++.dg/cpp0x/vt-51314.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/vt-51314.C	(revision 0)
@@ -0,0 +1,15 @@ 
+// { dg-options "-std=c++11" }
+// { dg-prune-output "invalid" }
+
+template<int>struct A{};
+template<class...U>void f(U...){
+    A<sizeof...U> x; // { dg-error "surrounded by parentheses" }
+}
+
+
+template<int...> struct Indices;
+template<class> struct Next_increasing_indices;
+template<int...I> struct Next_increasing_indices<Indices<I...> > {
+    typedef Indices<I...,sizeof...I> type; // { dg-error "surrounded by parentheses" }
+};
+

Property changes on: testsuite/g++.dg/cpp0x/vt-51314.C
___________________________________________________________________
Added: svn:eol-style
   + native
Added: svn:keywords
   + Author Date Id Revision URL

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 186616)
+++ cp/parser.c	(working copy)
@@ -21965,10 +21965,13 @@  cp_parser_sizeof_operand (cp_parser* par
 				 TYPENAME,
 				 /*initialized=*/0,
 				 /*attrlist=*/NULL);
 	}
     }
+  else if (pack_expansion_p)
+      error_at (cp_lexer_peek_token (parser->lexer)->location,
+	        "%<sizeof...%> argument must be surrounded by parentheses");
 
   /* If the type-id production did not work out, then we must be
      looking at the unary-expression production.  */
   if (!expr)
     expr = cp_parser_unary_expression (parser, /*address_p=*/false,