私は現在、PC-Lint(バージョン9.00jとl)に苦労しています。コードは正常にコンパイルされ、期待どおりに実行されます。メンバーテンプレートによる奇妙なPC-Lintエラー
#include <iostream>
#include <vector>
typedef unsigned char uint8_t;
class Test
{
uint8_t inputList[10];
std::vector<int> resultList;
public:
Test() : resultList()
{
for (uint8_t ii = 0; ii < 10; ++ii)
inputList[ii] = ii;
}
template<int list_size, typename ResultListType>
void loadList(const uint8_t (& inputList)[list_size],
ResultListType & resultList) const
{
for (uint8_t ii = 0; ii < list_size; ++ii)
resultList.push_back(inputList[ii]);
}
void run()
{
loadList(inputList, resultList);
}
void print()
{
std::vector<int>::iterator it;
for (it = resultList.begin(); it != resultList.end(); ++it)
std::cout << *it << std::endl;
}
};
int main()
{
Test t;
t.run();
t.print();
}
Gimpelのオンラインデモでこれを実行している、私はこれらのエラーや警告を得る:ここでの簡易版である
30 loadList(inputList, resultList);
diy.cpp 30 Error 1025: No template matches invocation 'Test::loadList(unsigned char [10], std::vector<int>)', 1 candidates found, 1 matched the argument count
diy.cpp 30 Info 1703: Function 'Test::loadList(const unsigned char (&)[V], <2>&) const' arbitrarily selected. Refer to Error 1025
diy.cpp 30 Error 1032: Member 'loadList' cannot be called without object
diy.cpp 30 Error 1058: While calling 'Test::loadList(const unsigned char (&)[V], <2>&) const': Initializing a non-const reference '<2>&' with a non-lvalue (a temporary object of type 'std::vector<int>')
diy.cpp 30 Warning 1514: Creating temporary to copy 'std::vector<int>' to '<2>&' (context: arg. no. 2)
だから基本的には、PC-lintはということを教えしようとしているが、それ偶然に正しいテンプレートパラメータを見つけるだけで、ベクトルの一時的なコピーだけが埋められます。しかし、コードは正常に実行され、resultListにはデータが含まれています。
ここで何が起こっているのか誰にでも教えてください。 PC-Lintは正しいのでしょうか?何かが間違っているのですか?これは単なるPC-Lintのバグですか?
constを省略すると、同じエラー/警告が表示されます。私はそれがエラー[1058](http://gimpel-online.com/MsgRef.html#1058) – craesh
@craeshの説明に記載されているので、追加しました。テンプレート引数を ' oadList <10、std :: vector>(inputList、resultList) 'です。 PCリントのテンプレートマッチングとオーバーロードの解決に問題があると慎重に言っています。 –
私はちょうど最初の引数、サイズを指定するだけで動作します。私は以前に似たような問題があったことを覚えています。これは 'lint -fvl'によって解決されました。可変長配列はGNU拡張であり、デフォルトのlint設定ではあいまいに有効になっています... – craesh