From 02b93ef2049aebf65772a58d1c5327d2bc51eeae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 21 Oct 2024 12:39:36 +0200 Subject: [PATCH 1/2] fix #376: Member access on user-defined literal tokenized incorrectly --- simplecpp.cpp | 3 ++- test.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 5bd5caca..f54af961 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -1002,7 +1002,8 @@ void simplecpp::TokenList::combineOperators() continue; } // float literals.. - if (tok->previous && tok->previous->number && sameline(tok->previous, tok)) { + if (tok->previous && tok->previous->number && sameline(tok->previous, tok) && tok->previous->str().find('_', 0) == std::string::npos + && tok->previous->str().find('.', 0) == std::string::npos) { tok->setstr(tok->previous->str() + '.'); deleteToken(tok->previous); if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp")))) { diff --git a/test.cpp b/test.cpp index d8e359e5..5b889789 100644 --- a/test.cpp +++ b/test.cpp @@ -390,6 +390,8 @@ static void combineOperators_floatliteral() ASSERT_EQUALS("0x1p+3f", preprocess("0x1p+3f")); ASSERT_EQUALS("0x1p+3L", preprocess("0x1p+3L")); ASSERT_EQUALS("1p + 3", preprocess("1p+3")); + ASSERT_EQUALS("1.0_a . b", preprocess("1.0_a.b")); + ASSERT_EQUALS("1_a . b", preprocess("1_a.b")); } static void combineOperators_increment() From d5d16096ef67a833fe7f993a6f1993b4fe84347d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 21 Oct 2024 14:02:04 +0200 Subject: [PATCH 2/2] use find_first_of --- simplecpp.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index f54af961..67e59abb 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -1002,8 +1002,7 @@ void simplecpp::TokenList::combineOperators() continue; } // float literals.. - if (tok->previous && tok->previous->number && sameline(tok->previous, tok) && tok->previous->str().find('_', 0) == std::string::npos - && tok->previous->str().find('.', 0) == std::string::npos) { + if (tok->previous && tok->previous->number && sameline(tok->previous, tok) && tok->previous->str().find_first_of("._") == std::string::npos) { tok->setstr(tok->previous->str() + '.'); deleteToken(tok->previous); if (sameline(tok, tok->next) && (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp")))) {