Skip to content

Commit 760532c

Browse files
committed
Add macro name for __VA_OPT__ syntax errors
1 parent 8c7287d commit 760532c

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

simplecpp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ namespace simplecpp {
17641764
for (const Token *tok = valueToken; tok && tok != endToken;) {
17651765
if (tok->str() == "__VA_OPT__") {
17661766
if (!sameline(tok, tok->next) || tok->next->op != '(')
1767-
throw Error(tok->location, "Missing opening parenthesis for __VA_OPT__");
1767+
throw Error(tok->location, "In definition of '" + nameTokDef->str() + "': Missing opening parenthesis for __VA_OPT__");
17681768
tok = tok->next->next;
17691769
int par = 1;
17701770
while (tok && tok != endToken) {
@@ -1773,7 +1773,7 @@ namespace simplecpp {
17731773
else if (tok->op == ')')
17741774
par--;
17751775
else if (tok->str() == "__VA_OPT__")
1776-
throw Error(tok->location, "__VA_OPT__ cannot be nested");
1776+
throw Error(tok->location, "In definition of '" + nameTokDef->str() + "': __VA_OPT__ cannot be nested");
17771777
if (par == 0) {
17781778
tok = tok->next;
17791779
break;
@@ -1783,7 +1783,7 @@ namespace simplecpp {
17831783
}
17841784
if (par != 0) {
17851785
const Token *const lastTok = expandValue.back() ? expandValue.back() : valueToken->next;
1786-
throw Error(lastTok->location, "Missing closing parenthesis for __VA_OPT__");
1786+
throw Error(lastTok->location, "In definition of '" + nameTokDef->str() + "': Missing closing parenthesis for __VA_OPT__");
17871787
}
17881788
} else {
17891789
expandValue.push_back(new Token(*tok));

test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ static void define_va_opt_3()
923923

924924
simplecpp::OutputList outputList;
925925
ASSERT_EQUALS("", preprocess(code1, &outputList));
926-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, Missing closing parenthesis for __VA_OPT__\n",
926+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': Missing closing parenthesis for __VA_OPT__\n",
927927
toString(outputList));
928928

929929
outputList.clear();
@@ -934,7 +934,7 @@ static void define_va_opt_3()
934934
"err()";
935935

936936
ASSERT_EQUALS("", preprocess(code2, &outputList));
937-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, Missing opening parenthesis for __VA_OPT__\n",
937+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': Missing opening parenthesis for __VA_OPT__\n",
938938
toString(outputList));
939939
}
940940

@@ -946,7 +946,7 @@ static void define_va_opt_4()
946946

947947
simplecpp::OutputList outputList;
948948
ASSERT_EQUALS("", preprocess(code1, &outputList));
949-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, Missing opening parenthesis for __VA_OPT__\n",
949+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': Missing opening parenthesis for __VA_OPT__\n",
950950
toString(outputList));
951951

952952
outputList.clear();
@@ -956,7 +956,7 @@ static void define_va_opt_4()
956956
"err()";
957957

958958
ASSERT_EQUALS("", preprocess(code2, &outputList));
959-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, Missing opening parenthesis for __VA_OPT__\n",
959+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': Missing opening parenthesis for __VA_OPT__\n",
960960
toString(outputList));
961961
}
962962

@@ -968,7 +968,7 @@ static void define_va_opt_5()
968968

969969
simplecpp::OutputList outputList;
970970
ASSERT_EQUALS("", preprocess(code, &outputList));
971-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, Missing opening parenthesis for __VA_OPT__\n",
971+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': Missing opening parenthesis for __VA_OPT__\n",
972972
toString(outputList));
973973
}
974974

@@ -980,7 +980,7 @@ static void define_va_opt_6()
980980

981981
simplecpp::OutputList outputList;
982982
ASSERT_EQUALS("", preprocess(code, &outputList));
983-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, __VA_OPT__ cannot be nested\n",
983+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': __VA_OPT__ cannot be nested\n",
984984
toString(outputList));
985985
}
986986

@@ -991,23 +991,23 @@ static void define_va_opt_7()
991991

992992
simplecpp::OutputList outputList;
993993
ASSERT_EQUALS("", preprocess(code1, &outputList));
994-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, Missing opening parenthesis for __VA_OPT__\n",
994+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': Missing opening parenthesis for __VA_OPT__\n",
995995
toString(outputList));
996996

997997
outputList.clear();
998998

999999
const char code2[] = "#define err(...) __VA_OPT__(";
10001000

10011001
ASSERT_EQUALS("", preprocess(code2, &outputList));
1002-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, Missing closing parenthesis for __VA_OPT__\n",
1002+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': Missing closing parenthesis for __VA_OPT__\n",
10031003
toString(outputList));
10041004

10051005
outputList.clear();
10061006

10071007
const char code3[] = "#define err(...) __VA_OPT__(x";
10081008

10091009
ASSERT_EQUALS("", preprocess(code3, &outputList));
1010-
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, Missing closing parenthesis for __VA_OPT__\n",
1010+
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define, In definition of 'err': Missing closing parenthesis for __VA_OPT__\n",
10111011
toString(outputList));
10121012
}
10131013

0 commit comments

Comments
 (0)