From 54287859f062ed48c22891f9cf10f740dcaf235f Mon Sep 17 00:00:00 2001 From: Hansruedi Patzen Date: Fri, 6 Apr 2018 17:01:48 +0200 Subject: [PATCH] Bug 533319: ASTRewrite parameter pack wrong pointer operators position Change-Id: I4798afa95d66aeed04b155ccd62a2b133f579296 Signed-off-by: Hansruedi Patzen --- .../ASTWriterDeclaratorTestSource.awts | 46 +++++++++++++++++++ .../rewrite/astwriter/DeclaratorWriter.java | 18 ++++---- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts index 7bf6cc650a9..fe03601af54 100644 --- a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts +++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterDeclaratorTestSource.awts @@ -178,3 +178,49 @@ constexpr long double operator ""_deg(long double deg) { return deg * 3.141592 / 180; } + +//!Memberfunction with varargs parameter without pointer ops +//%CPP +struct Foo +{ + template + void bar(ARGS... args) + { + } +}; + +//!Memberfunction with varargs parameter with pointer ops +//%CPP +struct Foo +{ + template + void bar(ARGS&&... args) + { + } +}; + +//!Template function with varargs parameter without pointer ops +//%CPP +template +void foo(ARGS... args) +{ +} + +//!Template function with varargs parameter with pointer ops +//%CPP +template +void foo(ARGS&&... args) +{ +} + +//!Function with varargs parameter without pointer ops +//%CPP +void foo(int arg, ...) +{ +} + +//!Function with varargs parameter with pointer ops +//%CPP +void foo(int&& arg, ...) +{ +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java index d331033c49a..4ea36fbcac3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java @@ -66,8 +66,6 @@ public class DeclaratorWriter extends NodeWriter { writeFieldDeclarator((IASTFieldDeclarator) declarator); } else if (declarator instanceof ICASTKnRFunctionDeclarator) { writeCKnRFunctionDeclarator((ICASTKnRFunctionDeclarator) declarator); - } else if (declarator instanceof ICPPASTDeclarator) { - writeCPPDeclarator((ICPPASTDeclarator) declarator); } else { writeDefaultDeclarator(declarator); } @@ -79,6 +77,7 @@ public class DeclaratorWriter extends NodeWriter { protected void writeDefaultDeclarator(IASTDeclarator declarator) { IASTPointerOperator[] pointOps = declarator.getPointerOperators(); writePointerOperators(declarator, pointOps); + writeParameterPack(declarator); IASTName name = declarator.getName(); name.accept(visitor); writeNestedDeclarator(declarator); @@ -97,6 +96,14 @@ public class DeclaratorWriter extends NodeWriter { } } + private void writeParameterPack(IASTDeclarator declarator) { + if (declarator instanceof ICPPASTDeclarator) { + if (((ICPPASTDeclarator) declarator).declaresParameterPack()) { + scribe.print(VAR_ARGS); + } + } + } + private void writeFunctionDeclarator(IASTStandardFunctionDeclarator funcDec) { IASTPointerOperator[] pointOps = funcDec.getPointerOperators(); writePointerOperators(funcDec, pointOps); @@ -330,11 +337,4 @@ public class DeclaratorWriter extends NodeWriter { protected void writeKnRParameterNames(ICASTKnRFunctionDeclarator knrFunct, IASTName[] parameterNames) { writeNodeList(parameterNames); } - - protected void writeCPPDeclarator(ICPPASTDeclarator declarator) { - if (declarator.declaresParameterPack()) { - scribe.print(VAR_ARGS); - } - writeDefaultDeclarator(declarator); - } }