Skip to content

Commit fe7f1c3

Browse files
committed
Fixed wrong locations in expanded macros
1 parent f0a9cee commit fe7f1c3

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

simplecpp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ namespace simplecpp {
14731473

14741474
const Token *appendTokens(TokenList *tokens,
14751475
const Location &rawloc,
1476-
const Token *lpar,
1476+
const Token * const lpar,
14771477
const std::map<TokenString,Macro> &macros,
14781478
const std::set<TokenString> &expandedmacros,
14791479
const std::vector<const Token*> &parametertokens) const {
@@ -1512,6 +1512,8 @@ namespace simplecpp {
15121512
tok = tok->next;
15131513
}
15141514
}
1515+
for (Token *tok2 = tokens->front(); tok2; tok2 = tok2->next)
1516+
tok2->location = lpar->location;
15151517
return sameline(lpar,tok) ? tok : NULL;
15161518
}
15171519

test.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,19 @@ static void define10() // don't combine prefix with space in macro
339339
ASSERT_EQUALS("\nu8 \"a b\" ;", preprocess(code));
340340
}
341341

342+
static void define11() // location of expanded argument
343+
{
344+
const char code[] = "#line 4 \"version.h\"\n"
345+
"#define A(x) B(x)\n"
346+
"#define B(x) x\n"
347+
"#define VER A(1)\n"
348+
"\n"
349+
"#line 10 \"cppcheck.cpp\"\n"
350+
"VER;";
351+
ASSERT_EQUALS("\n#line 10 \"cppcheck.cpp\"\n1 ;", preprocess(code));
352+
}
353+
354+
342355
static void define_invalid_1()
343356
{
344357
std::istringstream istr("#define A(\nB\n");
@@ -1911,6 +1924,7 @@ int main(int argc, char **argv)
19111924
TEST_CASE(define8);
19121925
TEST_CASE(define9);
19131926
TEST_CASE(define10);
1927+
TEST_CASE(define11);
19141928
TEST_CASE(define_invalid_1);
19151929
TEST_CASE(define_invalid_2);
19161930
TEST_CASE(define_define_1);

0 commit comments

Comments
 (0)