[英][[deprecated]] results in build failure in VS2017 (Error C4996)
[[deprecated]]
void foo(){};
int main()
{
foo();
}
上面的代碼在VS2017中產生以下錯誤:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1>deprecation.cpp
1>d:\source\deprecation.cpp(6): error C4996: 'foo': was declared deprecated
1>d:\source\deprecation.cpp(2): note: see declaration of 'foo'
1>Done building project "test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
不幸的是,搜索此錯誤會導致“如何使用[[deprecated]]”和“不贊成使用哪些功能”的問題。 樣式問題。
我檢查的每個資源似乎都建議使用[[deprecated]]應該和上面寫的一樣簡單-預期會出現編譯器錯誤/警告,但不是編譯失敗。 注釋掉[[deprecated]]行可成功構建。
項目的目標是Windows SDK版本10.0.17763.0。
cl.exe版本是19.16.27027。
我是否錯過了使用[[deprecated]]的顯而易見的東西,還是VS2017正在尋找打破它的方法?
您會收到一條錯誤警告,因為啟用了“ SDL檢查”。 它看起來像在VS17中默認啟用的SDL。 從文檔 :
/ sdl將這些警告作為錯誤 啟用 :
C4146 / we4146將一元減運算符應用於無符號類型,導致無符號結果。
C4308 / we4308負整數常數,轉換為無符號類型,可能導致無意義的結果。
C4532 / we4532在異常終止期間在__finally / finally塊中使用continue,break或goto關鍵字具有未定義的行為。
C4533 / we4533初始化變量的代碼將不會執行。
C4700 / we4700使用未初始化的局部變量。
C4703 / we4703使用可能未初始化的局部指針變量。
C4789 / we4789使用特定的C運行時間(CRT)功能時,緩沖區溢出。
C4995 / we4995已棄用標有pragma的功能。
C4996 / we4996使用標記為不推薦使用的功能。
要解決此問題,請轉到“屬性”->“ C / C ++”->“ SDL檢查”,將其設置為“否(/ sdl-)”。 在這之后你會得到
: warning C4996: 'foo': was declared deprecated
: note: see declaration of 'foo'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.