Bug 535331: Rewriting sizeof...() drops the parenthesis

Fix and test.

Change-Id: If54f24d833724f3c51ae0b6e7f325493e5110719
Signed-off-by: Hansruedi Patzen <hansruedi.patzen@hsr.ch>
Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterExpressionTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterExpressionTestSource.awts
index 0ca5a85..03e210b 100644
--- a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterExpressionTestSource.awts
+++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterExpressionTestSource.awts
@@ -241,3 +241,12 @@
         ;
     }
 };
+
+//!Operator sizeofParameterPack
+//%CPP
+template<typename... T> 
+void f(T... a)
+{
+    if (sizeof...(a)){
+    }
+}
\ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
index eec6ecf..26748d7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java
@@ -71,7 +71,7 @@
 	private static final String TYPEID_OP = "typeid ("; //$NON-NLS-1$
 	private static final String OPEN_BRACKET_OP = "("; //$NON-NLS-1$
 	private static final String SIZEOF_OP = "sizeof "; //$NON-NLS-1$
-	private static final String SIZEOF_PARAMETER_PACK_OP = "sizeof..."; //$NON-NLS-1$
+	private static final String SIZEOF_PARAMETER_PACK_OP = "sizeof...("; //$NON-NLS-1$
 	private static final String NOEXCEPT_OP = "noexcept ("; //$NON-NLS-1$
 	private static final String NOT_OP = "!"; //$NON-NLS-1$
 	private static final String TILDE_OP = "~"; //$NON-NLS-1$
@@ -274,6 +274,7 @@
 		case ICPPASTUnaryExpression.op_typeid:
 		case ICPPASTUnaryExpression.op_noexcept:
 		case IASTUnaryExpression.op_alignOf:
+		case IASTUnaryExpression.op_sizeofParameterPack:
 			return true;
 
 		default:
@@ -333,6 +334,7 @@
 		case ICPPASTUnaryExpression.op_noexcept:
 		case IASTUnaryExpression.op_bracketedPrimary:
 		case IASTUnaryExpression.op_alignOf:
+		case IASTUnaryExpression.op_sizeofParameterPack:
 			return CLOSING_BRACKET_OP;
 		default:
 			System.err.println("Unkwown unaryExpressionType " + unaryExpressionType); //$NON-NLS-1$
@@ -519,7 +521,7 @@
 		case IASTTypeIdExpression.op_typeof:
 			return TYPEOF_OP;
 		case IASTTypeIdExpression.op_sizeofParameterPack:
-			return SIZEOF_PARAMETER_PACK_OP + "("; //$NON-NLS-1$
+			return SIZEOF_PARAMETER_PACK_OP;
 		}
 		throw new IllegalArgumentException("Unknown TypeId Type"); //$NON-NLS-1$
 	}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
index f594759..a38417f 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
@@ -2669,9 +2669,7 @@
 		case IASTUnaryExpression.op_sizeofParameterPack:
 			scribe.printNextToken(Token.t_sizeof, scribe.printComment());
 			scribe.printNextToken(Token.tELIPSE, scribe.printComment());
-			if (peekNextToken() != Token.tLPAREN) {
-				scribe.space();
-			}
+			scribe.printNextToken(Token.tLPAREN);
 			operand.accept(this);
 			break;
 		case IASTUnaryExpression.op_throw:
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
index f98eeca..4055758 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
@@ -3405,4 +3405,19 @@
 	public void testFormatAttributedLabelStatements_Bug535266() throws Exception {
 		assertFormatterResult();
 	}
+
+	//template<typename ... T>
+	//void f(T ... a) {
+	//	if (sizeof...(a)) {
+	//	}
+	//}
+
+	//template<typename ... T>
+	//void f(T ... a) {
+	//	if (sizeof...(a)) {
+	//	}
+	//}
+	public void testIndendtionSizeofParampack_535331() throws Exception {
+		assertFormatterResult();
+	}
 }