Using "-x c++" with clang_parseTranslationUnit()

I'm trying to set the language to be used for parsing, with clang_parseTranslationUnit(). However, it appears that option is being ignored (causing the warning "warning: argument unused during compilation: '-x c++'" instead).

Am I doing something wrong ? Is this a known bug or limitation ?

Thanks,
         Stefan

I think it's because you don't pass it as 2 strings, "-x" and "c++"

Nope, I did pass it as separate arguments.

     Stefan

Could you post some code?

Here is the relevant snippet ('bpl' is an alias to boost::python, and cpp_flags is a Python list with additional compiler flags, such as -I..., -D..., etc.):

   char const **args = new char const*[bpl::len(cpp_flags) + 2];
   args[0] = "-x";
   args[1] = "c++";
   for (size_t i = 0; i != bpl::len(cpp_flags); ++i)
     args[i + 2] = bpl::extract<char const *>(cpp_flags[i]);

   CXIndex idx = clang_createIndex(0, 1);
   CXTranslationUnit_Flags flags = CXTranslationUnit_DetailedPreprocessingRecord;
   CXTranslationUnit tu =
     clang_parseTranslationUnit(idx, input_file,
                    args,
                    bpl::len(cpp_flags) + 2,
                    0, // unsaved_files
                    0, // num_unsaved_files
                    flags);

Running this on a C++ source file with extension '.h' will first warn about unused '-x c++', and then cause an error since its header search path doesn't include standard C++ headers.

(I'm in fact trying to parse clang code itself to generate a cross reference via Synopsis.)

Thanks,
         Stefan

What was happening was when creating the final argument list for clang, the given arguments were put after the input_file like this:

<input_file> ... -x c++ ..

in which case -x had no effect. This is fixed now in r127971. (Just FYI, it would not happen if you had passed the input file inside the array of args instead of using the input_file parameter).

-Argiris

Thanks ! Is there a chance to get this fix into the 2.9 release ?

     Stefan