[cfe-dev] clang-modernize: Can't get Loop Transform to work for STL for loops

GerdH gerd.hoeren at autodesk.com
Mon Mar 30 16:41:51 PDT 2015


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




--
View this message in context: http://clang-developers.42468.n3.nabble.com/clang-modernize-Can-t-get-Loop-Transform-to-work-for-STL-for-loops-tp4044770.html
Sent from the Clang Developers mailing list archive at Nabble.com.




More information about the cfe-dev mailing list