[cfe-dev] Clang: template functions

Frits van Bommel fvbommel at gmail.com
Fri Nov 5 04:27:22 PDT 2010


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;
  }



More information about the cfe-dev mailing list