Skip to content

Commit

Permalink
fix #13181: FP syntaxError with user-defined literal (#7172)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviggunne authored Jan 5, 2025
1 parent 8b764d8 commit 9871a09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void Token::update_property_info()
else if (mTokType != eVariable && mTokType != eFunction && mTokType != eType && mTokType != eKeyword)
tokType(eName);
} else if (simplecpp::Token::isNumberLike(mStr)) {
if (MathLib::isInt(mStr) || MathLib::isFloat(mStr))
if ((MathLib::isInt(mStr) || MathLib::isFloat(mStr)) && mStr.find('_') == std::string::npos)
tokType(eNumber);
else
tokType(eName); // assume it is a user defined literal
Expand Down
12 changes: 12 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(tokenize37); // #8550
TEST_CASE(tokenize38); // #9569
TEST_CASE(tokenize39); // #9771
TEST_CASE(tokenize40); // #13181

TEST_CASE(validate);

Expand Down Expand Up @@ -826,6 +827,17 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
}

void tokenize40() { // #13181
const char code[] = "struct A { double eps(double); };\n"
"A operator \"\"_a(long double);\n"
"void f() {\n"
" double d = 1.23;\n"
" if (d == 1.2_a .eps(.1)) {}\n"
"}\n";
(void) tokenizeAndStringify(code);
ASSERT_EQUALS("", errout_str());
}

void validate() {
// C++ code in C file
ASSERT_THROW_INTERNAL(tokenizeAndStringify(";using namespace std;",false,Platform::Type::Native,false), SYNTAX);
Expand Down

0 comments on commit 9871a09

Please sign in to comment.