LoginSignup
3
3

More than 5 years have passed since last update.

clang-format とコンパイルエラーが衝突した話

Posted at

コンパイルエラー

#include <vector>
...
std::vector<std::vector<int>> hoge;

これを書くと

error: '>>' should be '> >' within a nested template argument list

こんなコンパイルエラーが出る。>>> >は違うって意味ですね。

clang-format

じゃあ、スペースを入れようとするとどうなるかというと、clang-formatによってスペースが消されます。clang-formatを掛けなければ良い話ではあるのですが、私はC++のコードを書くときはclang-formatを保存時に自動で動かすようにしているのでわざわざそれをするのは嫌です。

解決策

clang-formatの-styleオプションに{SpacesInAngles: true}を指定すれば良い。すると、

#include <vector>
...
std::vector< std::vector< int > > hoge;

こうなる。
解決!

3
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3