Skip to content

Commit 9871a09

Browse files
authored
fix #13181: FP syntaxError with user-defined literal (#7172)
1 parent 8b764d8 commit 9871a09

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/token.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void Token::update_property_info()
126126
else if (mTokType != eVariable && mTokType != eFunction && mTokType != eType && mTokType != eKeyword)
127127
tokType(eName);
128128
} else if (simplecpp::Token::isNumberLike(mStr)) {
129-
if (MathLib::isInt(mStr) || MathLib::isFloat(mStr))
129+
if ((MathLib::isInt(mStr) || MathLib::isFloat(mStr)) && mStr.find('_') == std::string::npos)
130130
tokType(eNumber);
131131
else
132132
tokType(eName); // assume it is a user defined literal

test/testtokenize.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class TestTokenizer : public TestFixture {
7878
TEST_CASE(tokenize37); // #8550
7979
TEST_CASE(tokenize38); // #9569
8080
TEST_CASE(tokenize39); // #9771
81+
TEST_CASE(tokenize40); // #13181
8182

8283
TEST_CASE(validate);
8384

@@ -826,6 +827,17 @@ class TestTokenizer : public TestFixture {
826827
ASSERT_EQUALS(exp, tokenizeAndStringify(code));
827828
}
828829

830+
void tokenize40() { // #13181
831+
const char code[] = "struct A { double eps(double); };\n"
832+
"A operator \"\"_a(long double);\n"
833+
"void f() {\n"
834+
" double d = 1.23;\n"
835+
" if (d == 1.2_a .eps(.1)) {}\n"
836+
"}\n";
837+
(void) tokenizeAndStringify(code);
838+
ASSERT_EQUALS("", errout_str());
839+
}
840+
829841
void validate() {
830842
// C++ code in C file
831843
ASSERT_THROW_INTERNAL(tokenizeAndStringify(";using namespace std;",false,Platform::Type::Native,false), SYNTAX);

0 commit comments

Comments
 (0)