私は次のコードを持っています:
#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>
template<typename Iterator>
void foo(Iterator begin, Iterator end)
{
typedef typename std::iterator_traits<Iterator>::value_type type;
type smallest = (*std::min_element(begin,end));
std::cout << smallest << std::endl;
}
int main()
{
std::list<int> l;
l.push_back(1);
l.push_back(2);
foo(l.begin(),l.end());
return 0;
}
私がそれを次のようにコンパイルするとき:
g++ -pedantic -ansi -Wall -Werror -O2 -o test test.cpp
次のエラーが発生します。
cc1plus: warnings being treated as errors
In function ‘int main()’:
cc1plus: error: dereferencing pointer ‘pretmp.163’ does break strict-aliasing rules
cc1plus: note: initialized from here
このエラーはO3で見られますが、O1では見られません。私はcomeauオンラインコンパイラ、MSVC9.0およびiccv11を使用してコードをコンパイルしましたが、すべての場合でコードは問題なくコンパイルされます。
コードは、、、、、イテレータで正常に動作し、std :: std::vector
listの実装に非常に固有のもののようです。std::deque
std::set
char*
int*
この特定のエラー(警告)が何を意味するのか、そしてそれを解決する方法について誰かが洞察を提供してくれることを望んでいました。
注:GCCバージョンは次のとおりです。
gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.