Hello,
I’ve been using Clang as part of Xcode 5.02 on OS X 10.9 for over a year.
I’m trying clang-modernize for the first time. I’ve build llvm, clang and
its tools from sources on OS X 10.9.5. Clang-modernize works fine for
non-STL usage, but by default it can’t find STL headers:
> clang-modernize simple.cpp
/Users/gerd/Desktop/ServerOnMac/hoereng-mac-pro-ServerOnMac/Main/clang-modernize/simple.cpp:1:10:
fatal error: 'iostream' file not found
#include <iostream>
(The clang build instructions say it will try to find the best headers.)
I have a compile_commands.json file which contains my Xcode 5.02 Clang
invocation (including -std=c++11).
Clang-moderinze will find the STL headers if I add a –I to
compile_commands.json which points to my Xcode STL:
-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
But, it won’t replace the STL for{} loop in my example with a range-based
loop. Note that the “nullptr” and simple int array loops were updated as
expected.
How do I get this substation to work? Is there an STL compatibility issue
between this latest version of clang-modernize and Xcode 5.02?
Here’s the output of my test case from clang-modernize:
#include <iostream>
#include <vector>
void myfunc()
{
int *p = nullptr;
int arr = {1,2,3};
for (auto & elem : arr) {
std::cout << elem;
}
std::vector<int> my_container;
for (std::vector<int>::const_iterator I = my_container.begin(); I !=
my_container.end(); ++I) {
std::cout << *I << std::endl;
}
}