We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 56d8073 commit 40887caCopy full SHA for 40887ca
2 files changed
lib/preprocessor.cpp
@@ -2275,6 +2275,21 @@ static void skipstring(const std::string &line, std::string::size_type &pos)
2275
}
2276
2277
2278
+/**
2279
+ * Remove heading and trailing whitespaces from the input parameter.
2280
+ * #param s The string to trim.
2281
+ */
2282
+static std::string trim(const std::string& s)
2283
+{
2284
+ std::string::size_type beg = s.find_first_not_of(" \t");
2285
+ if (beg == std::string::npos)
2286
+ return s;
2287
+ std::string::size_type end = s.find_last_not_of(" \t");
2288
+ if (end == std::string::npos)
2289
+ return s.substr(beg);
2290
+ return s.substr(beg, end - beg + 1);
2291
+}
2292
+
2293
/**
2294
* @brief get parameters from code. For example 'foo(1,2)' => '1','2'
2295
* @param line in: The code
@@ -2319,7 +2334,7 @@ static void getparams(const std::string &line,
2319
2334
--parlevel;
2320
2335
if (parlevel <= 0) {
2321
2336
endFound = true;
2322
- params.push_back(par);
2337
+ params.push_back(trim(par));
2323
2338
break;
2324
2339
2325
2340
@@ -2342,7 +2357,7 @@ static void getparams(const std::string &line,
2342
2357
2343
2358
// new parameter
2344
2359
if (parlevel == 1 && line[pos] == ',') {
2345
2360
2346
2361
par = "";
2347
2362
2348
2363
test/testpreprocessor.cpp
@@ -178,6 +178,7 @@ class TestPreprocessor : public TestFixture {
178
TEST_CASE(macro_simple13);
179
TEST_CASE(macro_simple14);
180
TEST_CASE(macro_simple15);
181
+ TEST_CASE(macro_simple16); // #4703: Macro parameters not trimmed
182
TEST_CASE(macroInMacro1);
183
TEST_CASE(macroInMacro2);
184
TEST_CASE(macro_mismatch);
@@ -1927,6 +1928,12 @@ class TestPreprocessor : public TestFixture {
1927
1928
ASSERT_EQUALS("\n$\"foo\"\n", OurPreprocessor::expandMacros(filedata));
1929
1930
1931
+ void macro_simple16() { // # 4703
1932
+ const char filedata[] = "#define MACRO( A, B, C ) class A##B##C##Creator {};\n"
1933
+ "MACRO( B\t, U , G )";
1934
+ ASSERT_EQUALS("\n$class BUGCreator{};", OurPreprocessor::expandMacros(filedata));
1935
+ }
1936
1937
void macroInMacro1() {
1938
{
1939
const char filedata[] = "#define A(m) long n = m; n++;\n"
0 commit comments