☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

违反标准库函数要求的前置条件,除非标准库函数声明了这种情况会抛出异常

C++-Undefined-Behavior-87
目录 › next › previous

示例:

string s{"abc"};

cout << s[8];       // Undefined behavior
cout << s.at(8);    // Well-defined, throw out_of_range

标准规定 string::at 在参数超出范围时抛出 out_of_range 异常,而 string::operator [] 的参数超出范围会导致未定义的行为。

依据

ISO/IEC 14882:2003 17.4.3.8(1)-undefined ISO/IEC 14882:2011 17.6.4.11(1)-undefined
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.