================
@@ -444,51 +444,67 @@ TEST(CommandLineTest, TokenizeConfigFileTrailingComment) {
testCommandLineTokenizer(cl::tokenizeConfigFile, Input, Output);
}
+TEST(CommandLineTest, TokenizeConfigFileTrailingCommentNoNewline) {
+ const char *Input = "-c # comment";
+ const char *const Output[] = {"-c"};
+ testCommandLineTokenizer(cl::tokenizeConfigFile, Input, Output);
+}
+
+TEST(CommandLineTest, TokenizeConfigFileLineAfterComment) {
+ const char *Input = "-a # comment\n-b\n";
+ const char *const Output[] = {"-a", "-b"};
+ testCommandLineTokenizer(cl::tokenizeConfigFile, Input, Output);
+}
+
+TEST(CommandLineTest, TokenizeConfigFileNoContinuationInComment) {
+ // A backslash-newline inside a comment is not a continuation.
+ const char *Input = "-c # comment \\\n-d\n";
+ const char *const Output[] = {"-c", "-d"};
+ testCommandLineTokenizer(cl::tokenizeConfigFile, Input, Output);
+}
+
TEST(CommandLineTest, TokenizeConfigFileHashNotAtTokenStart) {
- // A '#' that does not begin a new token (i.e. is not preceded by
- // whitespace) is not a comment.
+ // '#' not preceded by whitespace is not a comment.
const char *Input = "-DFOO=1#2\n";
const char *const Output[] = {"-DFOO=1#2"};
testCommandLineTokenizer(cl::tokenizeConfigFile, Input, Output);
}
TEST(CommandLineTest, TokenizeConfigFileHashInQuotes) {
- // A '#' inside a quoted string is not a comment, but a '#' that begins a
- // new token after the closing quote still is.
const char *Input = "-DFOO=\"a # b\" # comment\n";
const char *const Output[] = {"-DFOO=a # b"};
testCommandLineTokenizer(cl::tokenizeConfigFile, Input, Output);
}
TEST(CommandLineTest, TokenizeConfigFileHashAfterClosingQuote) {
- // A '#' immediately after a closing quote, with no intervening
- // whitespace, does not begin a new token and so is not a comment.
const char *Input = "-DFOO=\"a\"#b\n";
const char *const Output[] = {"-DFOO=a#b"};
testCommandLineTokenizer(cl::tokenizeConfigFile, Input, Output);
}
+TEST(CommandLineTest, TokenizeConfigFileNewlineEndsQuote) {
+ // A literal newline ends the line even inside a quoted string.
+ const char *Input = "-DA=\"x\n-DB=y\n";
----------------
lenary wrote:
The docs point to backslash at the end of a line being a way to break long
arguments across lines. This would stop that being possible in a quoted
argument, but maybe that's ok? IMO this is likely to be a breaking change for
someone, somewhere.
I do think the case of breaking a quoted string is difficult to have
expectations for because it's not clear what to do with the newline, and
preventing breaking like that is probably better.
https://github.com/llvm/llvm-project/pull/213765
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits