From 0a3bfc24f84eaeb4bf8b209b1207f7d2e7a2cf2f Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Wed, 1 Sep 2010 17:09:42 +0200
Subject: [PATCH] Improved the expansion of variadic macros.

---
 src/libs/cplusplus/pp-macro-expander.cpp | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/libs/cplusplus/pp-macro-expander.cpp b/src/libs/cplusplus/pp-macro-expander.cpp
index ab6fe35ced2..78904e2227b 100644
--- a/src/libs/cplusplus/pp-macro-expander.cpp
+++ b/src/libs/cplusplus/pp-macro-expander.cpp
@@ -159,8 +159,9 @@ const char *MacroExpander::expand(const char *__first, const char *__last,
 
                 __result->append('\"');
             }
-            else
-                __result->append('#'); // ### warning message?
+            else {
+                // ### warning message?
+            }
         }
         else if (*__first == '\"')
         {
@@ -211,6 +212,17 @@ const char *MacroExpander::expand(const char *__first, const char *__last,
             // search for the paste token
             const char *next = skip_blanks (__first, __last);
             bool paste = false;
+
+            bool need_comma = false;
+            if (next != __last && *next == ',') {
+                const char *x = skip_blanks(__first + 1, __last);
+                if (x != __last && *x == '#' && (x + 1) != __last && x[1] == '#') {
+                    need_comma = true;
+                    paste = true;
+                    __first = skip_blanks(x + 2, __last);
+                }
+            }
+
             if (next != __last && *next == '#')
             {
                 paste = true;
@@ -220,8 +232,8 @@ const char *MacroExpander::expand(const char *__first, const char *__last,
             }
 
             const QByteArray fast_name(name_begin, name_end - name_begin);
-
-            if (const QByteArray *actual = resolve_formal (fast_name))
+            const QByteArray *actual = resolve_formal (fast_name);
+            if (actual)
             {
                 const char *begin = actual->constData ();
                 const char *end = begin + actual->size ();
@@ -233,6 +245,8 @@ const char *MacroExpander::expand(const char *__first, const char *__last,
                     ++end;
                 }
                 __result->append(begin, end - begin);
+                if (need_comma)
+                    __result->append(',');
                 continue;
             }
 
-- 
GitLab