我想在strostrup的std_lib_facilities.h頭文件(這裏是:http://stroustrup.com/Programming/PPP2code/std_lib_facilities.h)在macOS Sierra,Sublime Text 3(通過構建系統),蘋果LLVM版本8.0.0(clang-800.0.38)。我一直在擺弄各種各樣的設置,但一直沒有能夠避免兩個警告,即使開始「Hello,World!」程序編譯和運行:C++ Stroustrup的「std_lib_facilities.h」字符串結構 - 警告:無符號表達式的比較
std_lib_facilities.h:107:8: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
std_lib_facilities.h:113:8: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (i<0||size()<=i) throw Range_error(i);
~^~
,其中有問題的線的一部分:
// trivially range-checked string (no iterator checking):
struct String : std::string {
using size_type = std::string::size_type;
// using string::string;
char& operator[](unsigned int i) // rather than return at(i);
{
if (i<0||size()<=i) throw Range_error(i);
return std::string::operator[](i);
}
const char& operator[](unsigned int i) const
{
if (i<0||size()<=i) throw Range_error(i);
return std::string::operator[](i);
}
};
我的C++構建設置文件崇高文本從Can't build C++ program using Sublime Text 2複製我的編譯器似乎後沒有認識到Ç ++ 11中How do I update my compiler to use C++11 features?描述:
{
"cmd": ["g++", "-Wall", "-Wextra", "-pedantic", "-std=c++11", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ -Wall -Wextra -pedantic -std=c++11 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
我會很感激,如果有人可以幫助我瞭解爲什麼這些警告正在發生和解決次EM。
這意味着它是不可能的*無符號*值是負的,並作爲使得所述表達式的一部分總是會被*假*。 – WhozCraig
對,這很有道理 - 我想我一直假設Stroustrup不會寫這樣的冗餘,因此我的編譯器或其他工具的設置有問題。 – wander