C++ 記憶體安全提案 Safe C++ 公布!


C++ Alliance 組織和工程師 Sean Baxter 合作開發了 C++ 記憶體安全規範,並計畫將該提案提交給 ISO,以納入 C++ 標準。

採用 Safe C++ 撰寫的範例

#feature on safety
#include <std2.h>

int main() safe {
  std2::vector<int> vec { 11, 15, 20 };

  for(int x : vec) {
    // Ill-formed. mutate of vec invalidates iterator in ranged-for.
    if(x % 2)
      mut vec.push_back(x);

    std2::println(x);
  }
}

https://safecpp.org/P3390R0.html

留言

熱門文章