diff options
author | Shevek <[email protected]> | 2014-12-30 20:25:28 -0800 |
---|---|---|
committer | Shevek <[email protected]> | 2014-12-30 20:25:28 -0800 |
commit | c7b8f222102b6b8882ebe8c0d2b0255bf32817f7 (patch) | |
tree | 3987a44b8254ef3711b5d9aa674fd474cf44c528 /src/main/java/org/anarres/cpp | |
parent | 95b8b68bb3be229b7c3f52e7f53a232e1d7eb281 (diff) |
Fix #23: Allow empty anonymous variadic arguments.
Diffstat (limited to 'src/main/java/org/anarres/cpp')
-rw-r--r-- | src/main/java/org/anarres/cpp/Preprocessor.java | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/main/java/org/anarres/cpp/Preprocessor.java b/src/main/java/org/anarres/cpp/Preprocessor.java index f4e93cd..af3b896 100644 --- a/src/main/java/org/anarres/cpp/Preprocessor.java +++ b/src/main/java/org/anarres/cpp/Preprocessor.java @@ -784,15 +784,27 @@ public class Preprocessor implements Closeable { * is stripped from arguments. */ if (args.size() != m.getArgs()) { - error(tok, - "macro " + m.getName() - + " has " + m.getArgs() + " parameters " - + "but given " + args.size() + " args"); - /* We could replay the arg tokens, but I - * note that GNU cpp does exactly what we do, - * i.e. output the macro name and chew the args. - */ - return false; + if (m.isVariadic()) { + if (args.size() == m.getArgs() - 1) { + args.add(new Argument()); + } else { + error(tok, + "variadic macro " + m.getName() + + " has at least " + (m.getArgs() - 1) + " parameters " + + "but given " + args.size() + " args"); + return false; + } + } else { + error(tok, + "macro " + m.getName() + + " has " + m.getArgs() + " parameters " + + "but given " + args.size() + " args"); + /* We could replay the arg tokens, but I + * note that GNU cpp does exactly what we do, + * i.e. output the macro name and chew the args. + */ + return false; + } } for (Argument a : args) { |