Şu anda PC-Lint (sürüm 9.00j ve l) ile çalışıyorum, bu da bana bir kod parçası için bazı hatalar ve uyarılar veriyor. Kod iyi derler ve beklendiği gibi çalışır.Üye şablonları ile Garip PC-Lint hataları
#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 online demo bu çalışan, ben bu hataları ve uyarıları almak: İşte bunun basitleştirilmiş bir versiyonudur
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)
Yani temelde, PC-Lint söylemeye çalışıyor o Doğru şablon parametrelerini tesadüfen bulabilir ve sadece vektörün geçici bir kopyası doldurulacaktır. Ama kod iyi çalışıyor, sonuçListesi veriyi içeriyor!
Burada neler olup bittiğini söyleyen var mı? PC-Lint haklı ve bir şey yanlış mı yoksa bu sadece bir PC-Lint hatası mı?
Bu const kaldığında aynı hataları/uyarıları alıyorum. Ben hata [1058] (http://gimpel-online.com/MsgRef.html#1058) – craesh
@craesh açıklandığı gibi ekledim çünkü şablon argümanlarını açıkça belirtirseniz, oadList <10, std :: vektör> (inputList, sonuçListesi) '. PC-lint'te şablon eşleştirme ve aşırı yük çözünürlüğü ile ilgili bir sorun olduğunu belirtmek isterim. –
Sadece ilk argümanı, boyutunu belirtirseniz işe yarar. Bir süre önce benzer bir sorunu olduğunu hatırlıyorum, // lint -fvl ile çözüldü. Değişken uzunluk dizileri, varsayılan lint yapılandırmasında belirsiz bir şekilde etkinleştirilen bir GNU uzantısıdır ... – craesh