From 9871a09f3e12a38ff61edaef0abc94456bf50419 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 5 Jan 2025 12:31:24 +0100 Subject: [PATCH] fix #13181: FP syntaxError with user-defined literal (#7172) --- lib/token.cpp | 2 +- test/testtokenize.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/token.cpp b/lib/token.cpp index 4be1a973981..55ac12ad9ce 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -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 diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 85208b6fabe..bbebf933723 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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); @@ -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);