Skip to content

Commit 863489a

Browse files
Fix #615 User-defined literal created from alternative and (#620)
1 parent 4c06886 commit 863489a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

simplecpp.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,14 @@ static bool isFloatSuffix(const simplecpp::Token *tok)
10051005
return c == 'f' || c == 'l';
10061006
}
10071007

1008+
static const std::string AND("and");
1009+
static const std::string BITAND("bitand");
1010+
static const std::string BITOR("bitor");
1011+
static bool isAlternativeAndBitandBitor(const simplecpp::Token* tok)
1012+
{
1013+
return isAlternativeBinaryOp(tok, AND) || isAlternativeBinaryOp(tok, BITAND) || isAlternativeBinaryOp(tok, BITOR);
1014+
}
1015+
10081016
void simplecpp::TokenList::combineOperators()
10091017
{
10101018
std::stack<bool> executableScope;
@@ -1040,7 +1048,7 @@ void simplecpp::TokenList::combineOperators()
10401048
if (tok->previous && tok->previous->number && sameline(tok->previous, tok) && tok->previous->str().find_first_of("._") == std::string::npos) {
10411049
tok->setstr(tok->previous->str() + '.');
10421050
deleteToken(tok->previous);
1043-
if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp")))) {
1051+
if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp") && !isAlternativeAndBitandBitor(tok->next)))) {
10441052
tok->setstr(tok->str() + tok->next->str());
10451053
deleteToken(tok->next);
10461054
}
@@ -1285,8 +1293,6 @@ void simplecpp::TokenList::constFoldComparison(Token *tok)
12851293
}
12861294
}
12871295

1288-
static const std::string BITAND("bitand");
1289-
static const std::string BITOR("bitor");
12901296
static const std::string XOR("xor");
12911297
void simplecpp::TokenList::constFoldBitwise(Token *tok)
12921298
{
@@ -1321,7 +1327,6 @@ void simplecpp::TokenList::constFoldBitwise(Token *tok)
13211327
}
13221328
}
13231329

1324-
static const std::string AND("and");
13251330
static const std::string OR("or");
13261331
void simplecpp::TokenList::constFoldLogicalOp(Token *tok)
13271332
{

test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ static void combineOperators_floatliteral()
433433
ASSERT_EQUALS("1p + 3", preprocess("1p+3"));
434434
ASSERT_EQUALS("1.0_a . b", preprocess("1.0_a.b"));
435435
ASSERT_EQUALS("1_a . b", preprocess("1_a.b"));
436+
ASSERT_EQUALS("bool x = d != 0. and b ;", preprocess("bool x = d != 0. and b;"));
436437
}
437438

438439
static void combineOperators_increment()

0 commit comments

Comments
 (0)