http://llvm.org/bugs/show_bug.cgi?id=21505

            Bug ID: 21505
           Summary: Quoting in the compilation database example is wrong
           Product: Documentation
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: General docs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

... or at least misleading.

I'm talking about this page:
<http://clang.llvm.org/docs/JSONCompilationDatabase.html>.

The example compilation command is, in JSON:

"/usr/bin/clang++ -Irelative -DSOMEDEF=\"With spaces, quotes and \\-es.\" -c -o
file.o file.cc"

Unapplying the JSON quoting, we get the shell command:

/usr/bin/clang++ -Irelative -DSOMEDEF="With spaces, quotes and \-es." -c -o
file.o file.cc

Unapplying the shell quoting, we get the argument list:

/usr/bin/clang++
-Irelative
-DSOMEDEF=With spaces, quotes and \-es.
-c
-o
file.o
file.cc

(Or at least we should get this argument list. Note that in the shell syntax, \
isn't special unless followed by one of $`"\ or a newline:
<http://pubs.opengroup.org/onlinepubs/007904975/utilities/xcu_chap02.html#tag_02_02_03>.
However, testing shows that the backslash actually disappears at this stage, so
Clang probably implements this incorrectly.)

The -D argument, as written, produces a macro definition analogous to the
following:

#define SOMEDEF With spaces, quotes and \-es.

Which, I guess, is legal, but insensible. I doubt this definition can ever be
used in a legal C++ program.

Now, as far as what the correct command should be... I'm assuming the intention
is to yield a definition like this:

#define SOMEDEF "With spaces, quotes and \\-es."

Then the argument needs to be:

-DSOMEDEF="With spaces, quotes and \\-es."

Applying shell quoting gives us:

"-DSOMEDEF=\"With spaces, quotes and \\\\-es.\""

And applying JSON quoting (and adding the other arguments) yields:

"/usr/bin/clang++ -Irelative \"-DSOMEDEF=\\\"With spaces, quotes and
\\\\\\\\-es.\\\"\" -c -o file.o file.cc"

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to