Skip to content

Comments

Support C++14 quoted integer literals#11

Open
Zenju wants to merge 1 commit intofanf2:masterfrom
Zenju:patch-2
Open

Support C++14 quoted integer literals#11
Zenju wants to merge 1 commit intofanf2:masterfrom
Zenju:patch-2

Conversation

@Zenju
Copy link
Contributor

@Zenju Zenju commented Aug 31, 2020

Hi,

unifdef works great with my C++20 code base! There is just a minor issue with C++14 quoted integer literals: "Unterminated char literal", e.g. when a C++ source file contains: int num = 1'000'000;

The patch adds support und appears to work fine in my tests. Still it would be great if you could give it a quick review:

When quotes are detected inside an integer literal, the patch skips two characters until after the quote. This seems against the spirit of a function named "skipcomment()", because (part of) an integer literal is skipped, not a comment. Still I believe this should be fine, as the code calling skipcomment() only cares about preprocessor statements, and integer literals are not that. Is this assumption correct?

Best, Zenju

@xyshal
Copy link

xyshal commented Aug 23, 2021

Seems like you could also just not flag the beginning of a char literal if the previous char was a digit, or something like that?

diff --git a/unifdef.c b/unifdef.c
index dc145a2..d73dd5e 100644
--- a/unifdef.c
+++ b/unifdef.c
@@ -1260,6 +1260,7 @@ skipcomment(const char *cp)
                                incomment = CXX_COMMENT;
                                cp += 2;
                        } else if (strncmp(cp, "\'", 1) == 0) {
+                               if (isdigit((unsigned char)*(cp-1))) return cp;
                                incomment = CHAR_LITERAL;
                                linestate = LS_DIRTY;
                                cp += 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants