1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Craig Chaney <cchaney@us.ibm.com>

Fixed Bug 94365 - function-like macro with varargs requires one too many args
Patch for Devin Steffler
JUnit test case to protect against regression for 94365.
This commit is contained in:
John Camelon 2005-05-13 17:52:29 +00:00
parent 220206d7e9
commit 90f44f3db4
2 changed files with 23 additions and 3 deletions

View file

@ -3112,4 +3112,18 @@ public class AST2Tests extends AST2BaseTest {
}
assertEquals( count, sum );
}
public void testBug94365() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append( "#define ONE(a, ...) int x\n"); //$NON-NLS-1$
buffer.append( "#define TWO(b, args...) int y\n"); //$NON-NLS-1$
buffer.append( "int main()\n"); //$NON-NLS-1$
buffer.append( "{\n"); //$NON-NLS-1$
buffer.append( "ONE(\"string\"); /* err */\n"); //$NON-NLS-1$
buffer.append( "TWO(\"string\"); /* err */\n"); //$NON-NLS-1$
buffer.append( "return 0; \n"); //$NON-NLS-1$
buffer.append( "}\n"); //$NON-NLS-1$
parse( buffer.toString(), ParserLanguage.C );
}
}

View file

@ -3997,14 +3997,20 @@ abstract class BaseScanner implements IScanner {
argmap.put(arglist[currarg], arg);
}
int numArgs = arglist.length;
int numRequiredArgs = arglist.length;
for (int i = 0; i < arglist.length; i++) {
if (arglist[i] == null) {
numArgs = i;
numRequiredArgs = i;
break;
}
}
if (argmap.size() < numArgs) {
/* Don't require a match for the vararg placeholder */
/* Workaround for bugzilla 94365 */
if (macro.hasGCCVarArgs()|| macro.hasVarArgs())
numRequiredArgs--;
if (argmap.size() < numRequiredArgs) {
handleProblem(IProblem.PREPROCESSOR_MACRO_USAGE_ERROR,
bufferPos[bufferStackPos], macro.name);
}