Hi,

After watching Chandler Carruth's 
http://channel9.msdn.com/Events/GoingNative/2013/The-Care-and-Feeding-of-C-s-Dragons
 I decided to try the format and modernize examples in the middle of his 
presentation. After installing the latest LLVM suite, all examples without 
#include files work fine, both in clang-format and clang-modernize. Very 
impressive.

Using the native (Apple, Xcode) toolchain, I can cmake, make and run the 
example programs in a build directory directly under the source directory, e,g. 
clang-tools/vector/build under clang-tools/vector which contains vector.cpp and 
CMakeLists.txt.

But clang-modernize will fail *if* it contains a template based #include, e.g. 
Chandler's loop-convert example based on a small vector<int> loop.
Somehow I can't figure out how to specify the right flags for the 
compiler/linker in cmakelist.txt.

Any pointers appreciated!

Thanks,
Rob J. Goedman
[email protected]

------------/clang-tools/vector/vector.cpp------------

#include <vector>
#include <iostream>

int sum(const std::vector<int> &numbers) {
  int result = 0;
  for (std::vector<int>::const_iterator it = numbers.begin();
       it != numbers.end(); ++it) {
    result += *it;
  }
  return result;
}

int main() {
  std::vector<int> nums = { 1, 5, 6, 38 };
  std::cout << sum(nums) << std::endl;
}

-------------/clang-tools/vector/CMakeLists.Txt

project(foundations)
cmake_minimum_required(VERSION 2.8)

include_directories($ENV{GMOCK_HOME}/include $ENV{GMOCK_HOME}/gtest/include)
link_directories($ENV{GMOCK_HOME}/mybuild $ENV{GMOCK_HOME}/gtest/mybuild)
add_definitions(-stdlib=libc++ -std=c++11)

set(sources 
  vector.cpp
)

add_executable(test ${sources})
target_link_libraries(test pthread)
target_link_libraries(test gmock)
target_link_libraries(test gtest)

-----------------------

robs-15inch-2:build rob$ rm -rf *
robs-15inch-2:build rob$ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
-- The C compiler identification is Clang 5.0.0
-- The CXX compiler identification is Clang 5.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: 
/Users/rob/Projects/Languages/Cpp/clang_tools/vector/build
robs-15inch-2:build rob$ make
Scanning dependencies of target test
[100%] Building CXX object CMakeFiles/test.dir/vector.cpp.o
Linking CXX executable test
[100%] Built target test
robs-15inch-2:build rob$ ./test
50
robs-15inch-2:build rob$ clang-format -style LLVM -i ../vector.cpp 
robs-15inch-2:build rob$ clang-modernize -summary -p . -include ..
Parse: /Users/rob/Projects/Languages/Cpp/clang_tools/vector
/Users/rob/Projects/Languages/Cpp/clang_tools/vector/vector.cpp:1:10: fatal 
error: 'vector' file not found
#include <vector>
         ^
1 error generated.
Error while processing 
/Users/rob/Projects/Languages/Cpp/clang_tools/vector/vector.cpp.
Error encountered during translation.

_______________________________________________
cfe-users mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to