Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not confuse defines and designated initializers as float literals #299

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ void simplecpp::TokenList::combineOperators()
continue;
}
// float literals..
if (tok->previous && tok->previous->number) {
if (tok->previous && tok->previous->number && sameline(tok->previous, tok)) {
tok->setstr(tok->previous->str() + '.');
deleteToken(tok->previous);
if (isFloatSuffix(tok->next) || (tok->next && tok->next->startsWithOneOf("AaBbCcDdEeFfPp"))) {
Expand Down
18 changes: 18 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,23 @@ static void define11() // location of expanded argument
ASSERT_EQUALS("\n#line 10 \"cppcheck.cpp\"\n1 ;", preprocess(code));
}

static void define12()
{
const char code[] = "struct foo x = {\n"
" #define V 0\n"
" .x = V,\n"
"};\n";
ASSERT_EQUALS("struct foo x = {\n"
"# define V 0\n"
". x = V ,\n"
"} ;", readfile(code));
ASSERT_EQUALS("struct foo x = {\n"
"\n"
". x = 0 ,\n"
"} ;", preprocess(code));
}



static void define_invalid_1()
{
Expand Down Expand Up @@ -2617,6 +2634,7 @@ int main(int argc, char **argv)
TEST_CASE(define9);
TEST_CASE(define10);
TEST_CASE(define11);
TEST_CASE(define12);
TEST_CASE(define_invalid_1);
TEST_CASE(define_invalid_2);
TEST_CASE(define_define_1);
Expand Down