败犬日报 2024-12-20
1. noexcept 函数抛异常,要求诊断吗(编译会不会报错)
不要求。有 noexcept
的函数内抛异常是调用 std::terminate()
。
clang-tidy 有这个检查 https://clang.llvm.org/extra/clang-tidy/checks/bugprone/exception-escape.html。
2. clangd 罢工
是因为错误太多达到上限了,直接 fatal error 退出了。
可以设置 error limit 的上限避免这一点。
3. 调模板函数报 expected primary-expression before xxx token
cpp
template <typename T>
void foo(T t) {
t.bar<int>(); // error: expected primary-expression before 'int'
t.template bar<int>(); // OK
}
这是因为 t 的类型是模板类型,bar 就是个待决名,需要手动 template 消歧义。
4. 为什么 clang-format 没有将 boost 头文件和第三方库放一起
cpp
#include <fmt/format.h>
#include <glog/logging.h>
#include <boost/iterator/iterator_facade.hpp>
#include <cstddef>
#include <memory>
#include <ostream>
#include <tuple>
#include <utility>
这只是因为 boost 的扩展名是 "hpp"。
https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes