[cfe-dev] Clang: template functions

Sebastian Redl sebastian.redl at getdesigned.at
Fri Nov 5 04:56:24 PDT 2010


On 05.11.2010 12:27, Frits van Bommel wrote:
> On Fri, Nov 5, 2010 at 12:15 PM, Sebastian Redl
> <sebastian.redl at getdesigned.at>  wrote:
>> Sounds like you're trying to compile C++ code as C. Just because you
>> invoke Clang as clang++ doesn't mean it runs in C++ mode, it only means
>> it will link against the C++ runtime libraries. To actually compile in
>> C++ mode, the file must have a C++ extension (.cxx, .cpp or .cc), or you
>> have to override the language detection with the -x option.
> It does, actually. From clang/tools/driver/driver.cpp:
>
>    // Check for ".*++" or ".*++-[^-]*" to determine if we are a C++
>    // compiler. This matches things like "c++", "clang++", and "clang++-1.1".
>    //
>    // Note that we intentionally want to use argv[0] here, to support "clang++"
>    // being a symlink.
>    //
>    // We use *argv instead of argv[0] to work around a bogus g++ warning.
>    const char *progname = argv_[0];
>    std::string ProgName(llvm::sys::Path(progname).getBasename());
>    if (llvm::StringRef(ProgName).endswith("++") ||
>        llvm::StringRef(ProgName).rsplit('-').first.endswith("++")) {
>      TheDriver.CCCIsCXX = true;
>    }
That still doesn't mean that it will automatically use C++ as the input 
language. It might mean that it interprets .h files differently.

Sebastian



More information about the cfe-dev mailing list