@chengzhao-dev/dsh-cpp-workflow 0.6.19 → 0.6.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.en.md +6 -6
  2. package/README.md +6 -6
  3. package/lib/client.js +1 -1
  4. package/lib/comment-policy.js +1 -1
  5. package/lib/index.js +1 -1
  6. package/package.json +3 -3
  7. package/skills/building-cpp/SKILL.md +26 -13
  8. package/skills/building-cpp/project/vscode/01-extensions.md +22 -0
  9. package/skills/building-cpp/project/vscode/02-settings.md +33 -0
  10. package/skills/building-cpp/references/build-script.md +6 -6
  11. package/skills/building-cpp/references/environment.md +1 -1
  12. package/skills/building-cpp/steps/01-build.md +6 -6
  13. package/skills/building-cpp/steps/02-tooling.md +16 -8
  14. package/skills/building-cpp/steps/03-check.md +6 -6
  15. package/skills/developing-cpp/SKILL.md +27 -11
  16. package/skills/developing-cpp/scripts/checking-comments.mjs +3 -3
  17. package/skills/developing-cpp/{references/change-model.md → source/01-editing/01-edit-operations.md} +3 -3
  18. package/skills/developing-cpp/{references/priority.md → source/01-editing/02-rule-priority.md} +1 -1
  19. package/skills/developing-cpp/{references/google-cpp-style.md → source/02-style/01-google-cpp-style.md} +9 -9
  20. package/skills/developing-cpp/{references/project-design.md → source/03-design/01-project-design.md} +4 -4
  21. package/skills/developing-cpp/source/03-design/examples/behavior-sentence.md +14 -0
  22. package/skills/developing-cpp/source/03-design/examples/coordinate-table.md +31 -0
  23. package/skills/developing-cpp/source/03-design/examples/header-place.md +26 -0
  24. package/skills/developing-cpp/source/03-design/examples/library-boundary.md +30 -0
  25. package/skills/developing-cpp/source/03-design/examples/library-split.md +7 -0
  26. package/skills/developing-cpp/source/03-design/examples/move-result.md +39 -0
  27. package/skills/developing-cpp/source/03-design/examples/preview-read.md +40 -0
  28. package/skills/developing-cpp/{references/layout.md → source/04-layout/01-source-layout.md} +4 -4
  29. package/skills/developing-cpp/{references/file-template.md → source/04-layout/02-file-template.md} +2 -2
  30. package/skills/developing-cpp/{references/declaration-order.md → source/04-layout/03-declaration-order.md} +4 -4
  31. package/skills/developing-cpp/source/05-language/01-language-basics/01-objects.md +9 -0
  32. package/skills/developing-cpp/source/05-language/01-language-basics/02-initialization.md +19 -0
  33. package/skills/developing-cpp/source/05-language/01-language-basics/03-deduction.md +6 -0
  34. package/skills/developing-cpp/source/05-language/01-language-basics/04-const.md +15 -0
  35. package/skills/developing-cpp/source/05-language/01-language-basics/05-expressions.md +8 -0
  36. package/skills/developing-cpp/source/05-language/01-language-basics/06-functions.md +9 -0
  37. package/skills/developing-cpp/source/05-language/01-language-basics/07-classes.md +9 -0
  38. package/skills/developing-cpp/source/05-language/01-language-basics/08-raii.md +9 -0
  39. package/skills/developing-cpp/source/05-language/01-language-basics/09-templates.md +20 -0
  40. package/skills/developing-cpp/source/05-language/01-language-basics/10-checklist.md +9 -0
  41. package/skills/developing-cpp/source/05-language/02-value-types/01-width.md +11 -0
  42. package/skills/developing-cpp/source/05-language/02-value-types/02-signed.md +20 -0
  43. package/skills/developing-cpp/source/05-language/02-value-types/03-integer-roles.md +23 -0
  44. package/skills/developing-cpp/source/05-language/02-value-types/04-enum.md +17 -0
  45. package/skills/developing-cpp/source/05-language/02-value-types/05-strong-type.md +17 -0
  46. package/skills/developing-cpp/source/05-language/02-value-types/06-const-method.md +17 -0
  47. package/skills/developing-cpp/source/05-language/02-value-types/07-nodiscard.md +9 -0
  48. package/skills/developing-cpp/source/05-language/02-value-types/08-comparison.md +4 -0
  49. package/skills/developing-cpp/source/05-language/02-value-types/09-subscript.md +14 -0
  50. package/skills/developing-cpp/source/05-language/02-value-types/10-float-bool.md +7 -0
  51. package/skills/developing-cpp/source/05-language/02-value-types/11-checklist.md +8 -0
  52. package/skills/developing-cpp/source/05-language/03-standard-library/01-containers.md +23 -0
  53. package/skills/developing-cpp/source/05-language/03-standard-library/02-access.md +8 -0
  54. package/skills/developing-cpp/source/05-language/03-standard-library/03-iteration.md +12 -0
  55. package/skills/developing-cpp/source/05-language/03-standard-library/04-algorithms.md +20 -0
  56. package/skills/developing-cpp/source/05-language/03-standard-library/05-string.md +7 -0
  57. package/skills/developing-cpp/source/05-language/03-standard-library/06-format.md +44 -0
  58. package/skills/developing-cpp/source/05-language/03-standard-library/07-time.md +3 -0
  59. package/skills/developing-cpp/source/05-language/03-standard-library/08-random.md +3 -0
  60. package/skills/developing-cpp/source/05-language/03-standard-library/09-files.md +4 -0
  61. package/skills/developing-cpp/source/05-language/03-standard-library/10-checklist.md +9 -0
  62. package/skills/developing-cpp/source/05-language/04-performance/01-measure.md +15 -0
  63. package/skills/developing-cpp/source/05-language/04-performance/02-complexity.md +7 -0
  64. package/skills/developing-cpp/source/05-language/04-performance/03-memory.md +8 -0
  65. package/skills/developing-cpp/source/05-language/04-performance/04-undefined-behavior.md +20 -0
  66. package/skills/developing-cpp/source/05-language/04-performance/05-pitfalls.md +11 -0
  67. package/skills/developing-cpp/source/05-language/04-performance/06-false-optimizations.md +6 -0
  68. package/skills/developing-cpp/source/05-language/04-performance/07-checklist.md +8 -0
  69. package/skills/developing-cpp/{references/glossary.md → source/05-language/glossary/language-terms.md} +2 -2
  70. package/skills/developing-cpp/{references/naming.md → source/06-naming/01-identifier-names.md} +8 -6
  71. package/skills/developing-cpp/source/06-naming/examples/naming-accessor.md +17 -0
  72. package/skills/developing-cpp/source/06-naming/examples/naming-basic.md +3 -0
  73. package/skills/developing-cpp/source/06-naming/examples/naming-current-prefix.md +19 -0
  74. package/skills/developing-cpp/source/06-naming/examples/naming-lookup.md +18 -0
  75. package/skills/developing-cpp/source/06-naming/examples/naming-lower-layer.md +39 -0
  76. package/skills/developing-cpp/source/06-naming/examples/naming-multiple-return.md +20 -0
  77. package/skills/developing-cpp/source/06-naming/examples/naming-player-mark.md +17 -0
  78. package/skills/developing-cpp/source/06-naming/examples/naming-predicate.md +18 -0
  79. package/skills/developing-cpp/source/06-naming/examples/naming-rename.md +5 -0
  80. package/skills/developing-cpp/source/06-naming/examples/naming-responsibility.md +19 -0
  81. package/skills/developing-cpp/source/06-naming/examples/naming-role.md +21 -0
  82. package/skills/developing-cpp/source/06-naming/examples/naming-state-change.md +57 -0
  83. package/skills/developing-cpp/{references/comments.md → source/07-comments/01-comment-rules.md} +40 -24
  84. package/skills/developing-cpp/source/07-comments/examples/declaration-class.md +44 -0
  85. package/skills/developing-cpp/source/07-comments/examples/declaration-constructor.md +22 -0
  86. package/skills/developing-cpp/source/07-comments/examples/declaration-enum.md +24 -0
  87. package/skills/developing-cpp/source/07-comments/examples/declaration-file.md +66 -0
  88. package/skills/developing-cpp/source/07-comments/examples/declaration-function.md +100 -0
  89. package/skills/developing-cpp/source/07-comments/examples/declaration-member.md +25 -0
  90. package/skills/developing-cpp/source/07-comments/examples/declaration-predicate.md +13 -0
  91. package/skills/developing-cpp/source/07-comments/examples/declaration-struct.md +18 -0
  92. package/skills/developing-cpp/source/07-comments/examples/implementation-body.md +42 -0
  93. package/skills/developing-cpp/source/07-comments/examples/implementation-todo.md +16 -0
  94. package/skills/developing-cpp/{references → source/07-comments/glossary}/comment-terms.md +17 -17
  95. package/skills/developing-cpp/{references/exceptions.md → source/08-exceptions/01-throw-rules.md} +13 -11
  96. package/skills/developing-cpp/source/08-exceptions/examples/throw-boundary.md +28 -0
  97. package/skills/developing-cpp/source/08-exceptions/examples/throw-build-mode.md +38 -0
  98. package/skills/developing-cpp/source/08-exceptions/examples/throw-catch.md +21 -0
  99. package/skills/developing-cpp/source/08-exceptions/examples/throw-destructor.md +21 -0
  100. package/skills/developing-cpp/source/08-exceptions/examples/throw-format.md +13 -0
  101. package/skills/developing-cpp/source/08-exceptions/examples/throw-message.md +17 -0
  102. package/skills/developing-cpp/source/08-exceptions/examples/throw-when.md +27 -0
  103. package/skills/developing-cpp/steps/01-behavior.md +5 -5
  104. package/skills/developing-cpp/steps/02-boundary.md +8 -8
  105. package/skills/developing-cpp/steps/03-declaration.md +11 -11
  106. package/skills/developing-cpp/steps/04-implementation.md +14 -14
  107. package/skills/engineering/SKILL.md +84 -0
  108. package/skills/{configuring-cmake/references/cmake.md → engineering/cmake/01-targets/01-rules.md} +3 -3
  109. package/skills/engineering/cmake/01-targets/examples/glob.md +22 -0
  110. package/skills/engineering/cmake/01-targets/examples/rpath.md +24 -0
  111. package/skills/{configuring-cmake/examples/cmake.md → engineering/cmake/01-targets/examples/target.md} +1 -69
  112. package/skills/{configuring-cmake/references/modules.md → engineering/cmake/02-modules/01-functions.md} +2 -2
  113. package/skills/{configuring-cmake/references/cxx-standard.md → engineering/cmake/03-standard/01-cxx-standard.md} +1 -1
  114. package/skills/engineering/cmake/03-standard/examples/standard.md +19 -0
  115. package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/README.md +6 -6
  116. package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++20/README.md +1 -1
  117. package/skills/{building-cpp/references/linking.md → engineering/cmake/linking/01-libraries.md} +1 -48
  118. package/skills/engineering/cmake/linking/02-rpath.md +17 -0
  119. package/skills/engineering/cmake/linking/03-undefined-reference.md +14 -0
  120. package/skills/engineering/cmake/linking/04-inspect.md +15 -0
  121. package/skills/{configuring-cmake → engineering/cmake}/steps/01-targets.md +3 -3
  122. package/skills/{configuring-cmake → engineering/cmake}/steps/02-modules.md +2 -2
  123. package/skills/{configuring-cmake → engineering/cmake}/steps/03-check.md +2 -2
  124. package/skills/{building-cpp/references/testing.md → engineering/cmake/testing/ctest.md} +3 -3
  125. package/skills/engineering/formatting/02-clang-format.md +14 -0
  126. package/skills/engineering/formatting/03-clang-tidy.md +51 -0
  127. package/skills/engineering/formatting/04-clangd.md +83 -0
  128. package/skills/engineering/formatting/examples/clang-format.md +17 -0
  129. package/skills/engineering/formatting/examples/clang-tidy.md +64 -0
  130. package/skills/{building-cpp/examples/tooling.md → engineering/formatting/examples/clangd.md} +1 -80
  131. package/templates/cpp-workflow-project/SKILL.md +1 -1
  132. package/skills/building-cpp/references/static-analysis.md +0 -148
  133. package/skills/configuring-cmake/SKILL.md +0 -68
  134. package/skills/developing-cpp/examples/comments-declaration.md +0 -313
  135. package/skills/developing-cpp/examples/comments-implementation.md +0 -66
  136. package/skills/developing-cpp/examples/exceptions.md +0 -173
  137. package/skills/developing-cpp/examples/naming.md +0 -168
  138. package/skills/developing-cpp/examples/structure.md +0 -194
  139. package/skills/developing-cpp/references/language.md +0 -123
  140. package/skills/developing-cpp/references/performance.md +0 -83
  141. package/skills/developing-cpp/references/standard-library.md +0 -138
  142. package/skills/developing-cpp/references/types.md +0 -154
  143. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++11/README.md +0 -0
  144. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++11/cmake-snippet.cmake +0 -0
  145. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++14/README.md +0 -0
  146. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++14/cmake-snippet.cmake +0 -0
  147. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++17/README.md +0 -0
  148. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++17/cmake-snippet.cmake +0 -0
  149. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++20/cmake-snippet.cmake +0 -0
  150. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++23/README.md +0 -0
  151. /package/skills/{building-cpp/references → engineering/cmake/03-standard}/standards/c++23/cmake-snippet.cmake +0 -0
  152. /package/skills/{configuring-cmake/assets/cmake → engineering/cmake/assets}/CompileSettings.cmake +0 -0
  153. /package/skills/{configuring-cmake/assets/cmake → engineering/cmake/assets}/LinkSettings.cmake +0 -0
  154. /package/skills/{building-cpp/references/encoding.md → engineering/formatting/01-encoding.md} +0 -0
  155. /package/skills/{building-cpp → engineering/formatting}/scripts/checking-encoding.mjs +0 -0
@@ -1,6 +1,6 @@
1
1
  # CMake
2
2
 
3
- 目标:一个编译器、Ninja、target-based 规则、可用的编译数据库。下面是最小形状和常见边界;工程模板仍由 `building-cpp` 提供,在 `../../building-cpp/assets/templates/projects/`,可复用的 CMake 函数在本技能的 `assets/cmake/`:`CompileSettings.cmake` 收标准与警告,`LinkSettings.cmake` 收构建期 RPATH 与 GoogleTest 依赖。
3
+ 目标:一个编译器、Ninja、target-based 规则、可用的编译数据库。下面是最小形状和常见边界;工程模板仍由 `building-cpp` 提供,在 `../../../building-cpp/assets/templates/projects/`,可复用的 CMake 函数在本技能的 `assets/cmake/`:`CompileSettings.cmake` 收标准与警告,`LinkSettings.cmake` 收构建期 RPATH 与 GoogleTest 依赖。
4
4
 
5
5
  ## 排版
6
6
 
@@ -66,14 +66,14 @@ CompileSettings_SetWarnings(greeting PRIVATE LEVEL standard)
66
66
 
67
67
  ## 标准与复用
68
68
 
69
- C++11–C++23 的两层声明、可见性、常见错误与验证见 `references/cxx-standard.md`。通用函数 `CompileSettings_SetCxxStandard(target visibility c++NN)` 在 `assets/cmake/CompileSettings.cmake`:
69
+ C++11–C++23 的两层声明、可见性、常见错误与验证见 `../03-standard/01-cxx-standard.md`。通用函数 `CompileSettings_SetCxxStandard(target visibility c++NN)` 在 `../assets/cmake/CompileSettings.cmake`:
70
70
 
71
71
  ```cmake
72
72
  CompileSettings_SetCxxStandard(app PRIVATE c++23)
73
73
  CompileSettings_SetCxxStandard(greeting PUBLIC c++20)
74
74
  ```
75
75
 
76
- 函数名不绑定单一标准;新增档位只改函数里的支持列表。模块何时抽、文件怎么放、怎么导入与测试见 `references/modules.md`。
76
+ 函数名不绑定单一标准;新增档位只改函数里的支持列表。模块何时抽、文件怎么放、怎么导入与测试见 `../02-modules/01-functions.md`。
77
77
 
78
78
  ## 警告等级
79
79
 
@@ -0,0 +1,22 @@
1
+ # 正反例:GLOB
2
+
3
+ **差**:
4
+
5
+ ```cmake
6
+ file(GLOB SOURCES "src/*.cpp")
7
+ add_executable(app ${SOURCES})
8
+ ```
9
+
10
+ 新增文件不触发重新配置;不同机器上的文件集合可能不同。
11
+
12
+ **好**:
13
+
14
+ ```cmake
15
+ add_executable(app
16
+ src/main.cpp
17
+ src/task_list.cpp
18
+ src/task_parser.cpp
19
+ )
20
+ ```
21
+
22
+ 显式列表,新增文件时改 CMake;diff 能看出变化。
@@ -0,0 +1,24 @@
1
+ # 正反例:共享库运行时路径
2
+
3
+ **差**:
4
+
5
+ ```bash
6
+ LD_LIBRARY_PATH=build/clang/lib ./build/clang/bin/app # 每次运行都要包一层
7
+ ```
8
+
9
+ **好**:
10
+
11
+ ```cmake
12
+ # LinkSettings.cmake 提供 RPATH 与 GoogleTest 依赖函数。
13
+ include(LinkSettings)
14
+
15
+ add_library(greeting SHARED greeting/src/greeting.cpp)
16
+ set_target_properties(greeting PROPERTIES
17
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
18
+
19
+ add_executable(app src/main.cpp)
20
+ target_link_libraries(app PRIVATE greeting)
21
+ LinkSettings_SetBuildRpath(app)
22
+ ```
23
+
24
+ 从 `build/<compiler>/bin/app` 直接启动即可找到同级 `../lib` 下的共享库;安装场景另配 RPATH。
@@ -1,4 +1,4 @@
1
- # 正反例:CMake
1
+ # 正反例:target 与输出目录
2
2
 
3
3
  ## 最小可用形状
4
4
 
@@ -44,29 +44,6 @@ target_include_directories(greeting PUBLIC greeting/include)
44
44
  target_link_libraries(app PRIVATE greeting)
45
45
  ```
46
46
 
47
- ## GLOB
48
-
49
- **差**:
50
-
51
- ```cmake
52
- file(GLOB SOURCES "src/*.cpp")
53
- add_executable(app ${SOURCES})
54
- ```
55
-
56
- 新增文件不触发重新配置;不同机器上的文件集合可能不同。
57
-
58
- **好**:
59
-
60
- ```cmake
61
- add_executable(app
62
- src/main.cpp
63
- src/task_list.cpp
64
- src/task_parser.cpp
65
- )
66
- ```
67
-
68
- 显式列表,新增文件时改 CMake;diff 能看出变化。
69
-
70
47
  ## 把 `main()` 编进库
71
48
 
72
49
  **差**:
@@ -86,26 +63,6 @@ target_link_libraries(app PRIVATE core)
86
63
 
87
64
  库不依赖 `main()`;测试链接库时不会碰到入口。
88
65
 
89
- ## 标准只写一半
90
-
91
- **差**:
92
-
93
- ```cmake
94
- target_compile_features(app PRIVATE cxx_std_20)
95
- # 没写 CXX_STANDARD_REQUIRED;编译器不支持时可能静默降级
96
- set_target_properties(app PROPERTIES CXX_STANDARD 20)
97
- ```
98
-
99
- 问题:meta-feature 只保证“至少”,`CXX_STANDARD` 又允许 decay,实际标准可能不是 20。
100
-
101
- **好**:
102
-
103
- ```cmake
104
- CompileSettings_SetCxxStandard(app PRIVATE c++20)
105
- ```
106
-
107
- 两套声明同时写;`CXX_STANDARD_REQUIRED ON` 禁止降级,`CXX_EXTENSIONS OFF` 把 `gnu++20` 收成 `c++20`。
108
-
109
66
  ## 警告等级
110
67
 
111
68
  **差**:
@@ -150,31 +107,6 @@ ln -s clang/compile_commands.json build/compile_commands.json
150
107
  clang-tidy -p build/clang src/main.cpp
151
108
  ```
152
109
 
153
- ## 共享库运行时路径
154
-
155
- **差**:
156
-
157
- ```bash
158
- LD_LIBRARY_PATH=build/clang/lib ./build/clang/bin/app # 每次运行都要包一层
159
- ```
160
-
161
- **好**:
162
-
163
- ```cmake
164
- # LinkSettings.cmake 提供 RPATH 与 GoogleTest 依赖函数。
165
- include(LinkSettings)
166
-
167
- add_library(greeting SHARED greeting/src/greeting.cpp)
168
- set_target_properties(greeting PROPERTIES
169
- LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
170
-
171
- add_executable(app src/main.cpp)
172
- target_link_libraries(app PRIVATE greeting)
173
- LinkSettings_SetBuildRpath(app)
174
- ```
175
-
176
- 从 `build/<compiler>/bin/app` 直接启动即可找到同级 `../lib` 下的共享库;安装场景另配 RPATH。
177
-
178
110
  ## 输出目录
179
111
 
180
112
  **差**:可执行文件生成在源码根,`git status` 出现 `app`、`*.o`。
@@ -74,7 +74,7 @@ endfunction()
74
74
 
75
75
  ## 契约注释
76
76
 
77
- 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` 标位置参数、`:keyword` 标关键字参数;不写 `#[[.rst:` 与 `.. command::`,那是进 CMake 手册的模块才用的标记。同一文件的函数组之间用一条 `#---` 分隔,行注释只写原因,不画 `#===...===#` 方框。完整写法见 `references/cmake.md`。
77
+ 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` 标位置参数、`:keyword` 标关键字参数;不写 `#[[.rst:` 与 `.. command::`,那是进 CMake 手册的模块才用的标记。同一文件的函数组之间用一条 `#---` 分隔,行注释只写原因,不画 `#===...===#` 方框。完整写法见 `../01-targets/01-rules.md`。
78
78
 
79
79
  ## 测试
80
80
 
@@ -86,7 +86,7 @@ endfunction()
86
86
  4. 重复 `include()` 不报函数重定义。
87
87
  5. `compile_commands.json` 出现对应 `-std=`。
88
88
 
89
- 测试完删除临时工程;不把测试用 `CMakeLists.txt` 留在仓库。真实工程里的验证由 `steps/03-check.md` 完成。
89
+ 测试完删除临时工程;不把测试用 `CMakeLists.txt` 留在仓库。真实工程里的验证由 `../steps/03-check.md` 完成。
90
90
 
91
91
  ## 迁移旧模块
92
92
 
@@ -21,7 +21,7 @@ CMake 有两套相关机制,必须同时写:
21
21
 
22
22
  ## 通用函数
23
23
 
24
- `assets/cmake/CompileSettings.cmake` 提供:
24
+ `../assets/cmake/CompileSettings.cmake` 提供:
25
25
 
26
26
  ```cmake
27
27
  CompileSettings_SetCxxStandard(app PRIVATE c++23)
@@ -0,0 +1,19 @@
1
+ # 正反例:标准只写一半
2
+
3
+ **差**:
4
+
5
+ ```cmake
6
+ target_compile_features(app PRIVATE cxx_std_20)
7
+ # 没写 CXX_STANDARD_REQUIRED;编译器不支持时可能静默降级
8
+ set_target_properties(app PROPERTIES CXX_STANDARD 20)
9
+ ```
10
+
11
+ 问题:meta-feature 只保证“至少”,`CXX_STANDARD` 又允许 decay,实际标准可能不是 20。
12
+
13
+ **好**:
14
+
15
+ ```cmake
16
+ CompileSettings_SetCxxStandard(app PRIVATE c++20)
17
+ ```
18
+
19
+ 两套声明同时写;`CXX_STANDARD_REQUIRED ON` 禁止降级,`CXX_EXTENSIONS OFF` 把 `gnu++20` 收成 `c++20`。
@@ -4,7 +4,7 @@
4
4
 
5
5
  每个标准单独一个目录:`c++11/`、`c++14/`、`c++17/`、`c++20/`、`c++23/`。目录里放这一档自己的编译器下限、语言/库设施、CMake 片段和工具映射;模板仍然只有一套公共骨架,靠 `__cplusplus` 条件选择实现,不复制五份模板。
6
6
 
7
- Google C++ Style Guide 上游仍写 “target C++20”,本工作流默认 C++23 是一处明确偏离;Google 的排版、命名、头文件和异常之外的规则不变。异常政策仍按 [exceptions.md](../../../developing-cpp/references/exceptions.md)。
7
+ Google C++ Style Guide 上游仍写 “target C++20”,本工作流默认 C++23 是一处明确偏离;Google 的排版、命名、头文件和异常之外的规则不变。异常政策仍按 [exceptions.md](../../../../developing-cpp/source/08-exceptions/01-throw-rules.md)。
8
8
 
9
9
  ## 选择标准
10
10
 
@@ -145,7 +145,7 @@ target_link_options(app PRIVATE -stdlib=libc++)
145
145
  | `c++20` | 必测 | 必测 | 必测 | `c++20` | `c++20` | 读 DB |
146
146
  | `c++23` | 必测 | 必测 | 必测 | `c++23` | `Latest` | 读 DB |
147
147
 
148
- 本仓库在 WSL(clang 21.1.8、CMake 4.2.3、Ninja 1.13.2)上跑过四套模板 × 五档共 20 个构建:single、multi、static-library、shared-library 全部 configure/build/CTest 通过,`compile_commands.json` 都得到精确的 `-std=c++11/14/17/20/23`。模板用 `__cplusplus` 条件选择 `std::format` 或字符串拼接,默认仍交付 C++23。可复现脚本:[checking-standard-matrix.sh](../../../../scripts/checking-standard-matrix.sh)。
148
+ 本仓库在 WSL(clang 21.1.8、CMake 4.2.3、Ninja 1.13.2)上跑过四套模板 × 五档共 20 个构建:single、multi、static-library、shared-library 全部 configure/build/CTest 通过,`compile_commands.json` 都得到精确的 `-std=c++11/14/17/20/23`。模板用 `__cplusplus` 条件选择 `std::format` 或字符串拼接,默认仍交付 C++23。可复现脚本:[checking-standard-matrix.sh](../../../../../scripts/checking-standard-matrix.sh)。
149
149
 
150
150
  ## 新增标准
151
151
 
@@ -159,7 +159,7 @@ target_link_options(app PRIVATE -stdlib=libc++)
159
159
 
160
160
  ## 相关文件
161
161
 
162
- - [environment.md](../environment.md):四轴声明与校验。
163
- - [configuring-cmake/references/cxx-standard.md](../../../configuring-cmake/references/cxx-standard.md):C++11–C++23 在 CMake 里的两层声明与验证。
164
- - [static-analysis.md](../static-analysis.md):clang-format / clang-tidy / clangd 分工。
165
- - [01-build.md](../../steps/01-build.md):定构建步骤。
162
+ - [environment.md](../../../../building-cpp/references/environment.md):四轴声明与校验。
163
+ - [cxx-standard.md](../01-cxx-standard.md):C++11–C++23 在 CMake 里的两层声明与验证。
164
+ - [clang-tidy.md](../../../formatting/03-clang-tidy.md):clang-format / clang-tidy / clangd 分工。
165
+ - [01-build.md](../../../../building-cpp/steps/01-build.md):定构建步骤。
@@ -22,7 +22,7 @@
22
22
  - C++17 的全部内容。
23
23
  - concepts、requires、ranges、`std::span`、`std::bit_cast`、`std::source_location`。
24
24
  - `std::format`、协程、`std::jthread`、三路比较。
25
- - 按成员逐项比较时写成 `bool operator==(const T&) const = default`。C++23 沿用,不另写一遍。
25
+ - 调用方需要按成员逐项比较时,写成 `bool operator==(const T&) const = default`。C++23 沿用,不另写一遍。
26
26
  - 模块语法(工具链支持不完整,模板不使用)。
27
27
 
28
28
  ## 本档不能假设
@@ -1,6 +1,4 @@
1
- # 从源文件到可执行文件
2
-
3
- 链接错误和编译错误是两类问题。先判断失败发生在哪个阶段,再改对应的文件。
1
+ # 链接与库边界
4
2
 
5
3
  ## 四个阶段
6
4
 
@@ -25,19 +23,6 @@
25
23
  - 只用到声明时不要包含完整定义;前置声明可以减少编译依赖,但不能替代需要完整类型的场景(继承、成员对象、按值返回)。
26
24
  - 每个头文件自包含:单独编译一个只包含该头文件的 `.cpp` 应通过。用路径式 `#define` 守卫防止重复包含,不用 `#pragma once`。
27
25
 
28
- ## `undefined reference` 分诊
29
-
30
- | 现象 | 常见原因 | 修法 |
31
- | --- | --- | --- |
32
- | 链接器说某个成员函数未定义 | 声明了但没写定义,或 `.cpp` 没加入 target | 补定义,或把源文件加入 `target_sources` |
33
- | 只有某个平台失败 | 条件编译把定义排除了 | 检查宏和平台分支,保证每个平台都有定义 |
34
- | 第三方库符号缺失 | 没链接库,或库顺序不对 | `target_link_libraries` 加库;CMake 会处理顺序 |
35
- | C++ 符号被当成 C 符号 | 头文件缺少 `extern \"C\"` | C 接口头加 `extern \"C\"`,C++ 调用方也可见 |
36
- | 模板成员未定义 | 模板定义在 `.cpp`,实例化点看不到 | 模板定义移到头文件,或显式实例化 |
37
- | 静态库中的目标文件没被拉入 | 链接器只取被引用符号所在的目标文件 | 确认符号确实被引用,或改用对象库/共享库 |
38
-
39
- 先看链接器报的完整符号名和来源文件,不要只看第一行。
40
-
41
26
  ## 静态库与共享库
42
27
 
43
28
  | 形式 | 产物 | 链接时机 | 运行期依赖 | 适用 |
@@ -50,38 +35,6 @@
50
35
  - 共享库的 ABI 包括类布局、虚表、标准库类型和编译器选项;不同编译器或 `-stdlib` 混用可能链接成功但运行崩溃。
51
36
  - 一个项目里不要同时链接两套标准库(libstdc++ 与 libc++);编译器、clangd、库和可执行文件必须一致。
52
37
 
53
- ## 输出目录与 RPATH
54
-
55
- 推荐布局:
56
-
57
- ```text
58
- build/<compiler>/
59
- bin/app
60
- lib/libgame.so
61
- compile_commands.json
62
- ```
63
-
64
- - 可执行文件在 `bin/`,共享库在 `lib/`;不要把库和可执行文件混在同一层。
65
- - 运行时动态加载器默认不搜索可执行文件旁边的 `lib/`;需要 RPATH:
66
- - Linux:`-Wl,-rpath,'$ORIGIN/../lib'`
67
- - macOS:`-Wl,-rpath,@loader_path/../lib`
68
- - CMake 用 `BUILD_RPATH` / `INSTALL_RPATH` 设置,不要手工拼链接命令;见 [`LinkSettings.cmake`](../../configuring-cmake/assets/cmake/LinkSettings.cmake)。
69
- - RPATH 里的 `$ORIGIN` 要防止被 shell 展开:CMake 字符串里写 `\$ORIGIN` 或使用 `BUILD_RPATH_USE_ORIGIN`。
70
-
71
- ## 验收:`file` 与 `ldd`
72
-
73
- 链接成功不等于能运行。构建后检查产物:
74
-
75
- ```bash
76
- file build/clang/bin/app
77
- ldd build/clang/bin/app
78
- ```
79
-
80
- - `file` 确认架构、位数、是否动态链接。
81
- - `ldd` 确认每个共享库都能解析到实际路径;出现 `not found` 就是加载期会失败。
82
- - 运行 `app` 做一次最小启动;动态库缺失会在启动时暴露,而不是链接时。
83
- - macOS 用 `otool -L` 代替 `ldd`;Windows 用 `dumpbin /dependents`。
84
-
85
38
  ## 构建脚本里的顺序
86
39
 
87
40
  1. 配置:CMake 生成构建系统,导出编译数据库。
@@ -0,0 +1,17 @@
1
+ # 输出目录与 RPATH
2
+
3
+ 推荐布局:
4
+
5
+ ```text
6
+ build/<compiler>/
7
+ bin/app
8
+ lib/libgame.so
9
+ compile_commands.json
10
+ ```
11
+
12
+ - 可执行文件在 `bin/`,共享库在 `lib/`;不要把库和可执行文件混在同一层。
13
+ - 运行时动态加载器默认不搜索可执行文件旁边的 `lib/`;需要 RPATH:
14
+ - Linux:`-Wl,-rpath,'$ORIGIN/../lib'`
15
+ - macOS:`-Wl,-rpath,@loader_path/../lib`
16
+ - CMake 用 `BUILD_RPATH` / `INSTALL_RPATH` 设置,不要手工拼链接命令;见 [`LinkSettings.cmake`](../assets/LinkSettings.cmake)。
17
+ - RPATH 里的 `$ORIGIN` 要防止被 shell 展开:CMake 字符串里写 `\$ORIGIN` 或使用 `BUILD_RPATH_USE_ORIGIN`。
@@ -0,0 +1,14 @@
1
+ # undefined reference 分诊
2
+
3
+ ## `undefined reference` 分诊
4
+
5
+ | 现象 | 常见原因 | 修法 |
6
+ | --- | --- | --- |
7
+ | 链接器说某个成员函数未定义 | 声明了但没写定义,或 `.cpp` 没加入 target | 补定义,或把源文件加入 `target_sources` |
8
+ | 只有某个平台失败 | 条件编译把定义排除了 | 检查宏和平台分支,保证每个平台都有定义 |
9
+ | 第三方库符号缺失 | 没链接库,或库顺序不对 | `target_link_libraries` 加库;CMake 会处理顺序 |
10
+ | C++ 符号被当成 C 符号 | 头文件缺少 `extern \"C\"` | C 接口头加 `extern \"C\"`,C++ 调用方也可见 |
11
+ | 模板成员未定义 | 模板定义在 `.cpp`,实例化点看不到 | 模板定义移到头文件,或显式实例化 |
12
+ | 静态库中的目标文件没被拉入 | 链接器只取被引用符号所在的目标文件 | 确认符号确实被引用,或改用对象库/共享库 |
13
+
14
+ 先看链接器报的完整符号名和来源文件,不要只看第一行。
@@ -0,0 +1,15 @@
1
+ # 验收:file 与 ldd
2
+
3
+ ## 验收:`file` 与 `ldd`
4
+
5
+ 链接成功不等于能运行。构建后检查产物:
6
+
7
+ ```bash
8
+ file build/clang/bin/app
9
+ ldd build/clang/bin/app
10
+ ```
11
+
12
+ - `file` 确认架构、位数、是否动态链接。
13
+ - `ldd` 确认每个共享库都能解析到实际路径;出现 `not found` 就是加载期会失败。
14
+ - 运行 `app` 做一次最小启动;动态库缺失会在启动时暴露,而不是链接时。
15
+ - macOS 用 `otool -L` 代替 `ldd`;Windows 用 `dumpbin /dependents`。
@@ -24,7 +24,7 @@ target 规则:
24
24
  - 源文件显式列出;不写 `file(GLOB ...)`,新增文件时改 CMake。
25
25
  - `set(CMAKE_EXPORT_COMPILE_COMMANDS ON)`;可执行文件输出到 `build/<compiler>/bin`,库到 `build/<compiler>/lib`。
26
26
  - 需要直接运行构建产物的共享库程序,设 `BUILD_RPATH "$ORIGIN/../lib"`;Apple 用 `@loader_path/../lib`。
27
- - 标准用项目 `cmake/` 里的 `CompileSettings_SetCxxStandard(target visibility c++NN)`;没有这个函数时先从 `assets/cmake/CompileSettings.cmake` 复制并导入,不要在每个 target 重复三属性。
27
+ - 标准用项目 `cmake/` 里的 `CompileSettings_SetCxxStandard(target visibility c++NN)`;没有这个函数时先从 `../assets/cmake/CompileSettings.cmake` 复制并导入,不要在每个 target 重复三属性。
28
28
  - 警告用同一份 `CompileSettings.cmake` 里的 `CompileSettings_SetWarnings(target visibility LEVEL basic|standard|strict)`;`visibility` 用 `PRIVATE` 或 `INTERFACE`,不要在每个 target 重复 `-Wall` 列表。
29
29
 
30
30
  ## 命令形状
@@ -40,7 +40,7 @@ GCC 模式把目录和编译器换成 `build/gcc`、`g++`。一个 configure 只
40
40
 
41
41
  ## 情况
42
42
 
43
- **新工程**:工程模板仍由 `building-cpp` 提供,从 `../../building-cpp/assets/templates/projects/` 选形态,只复制目标工程缺的文件;模板里的 `{{PROJECT_NAME}}` 换成真实工程名,再按本节改 target 与标准。
43
+ **新工程**:工程模板仍由 `building-cpp` 提供,从 `../../../building-cpp/assets/templates/projects/` 选形态,只复制目标工程缺的文件;模板里的 `{{PROJECT_NAME}}` 换成真实工程名,再按本节改 target 与标准。
44
44
 
45
45
  **已有工程**:先读现有 `CMakeLists.txt`,找出全局设置、GLOB、输出目录和 target 命名;只改与当前任务相关的一处。大改前先让现有构建跑通,保留可回退点。
46
46
 
@@ -50,4 +50,4 @@ GCC 模式把目录和编译器换成 `build/gcc`、`g++`。一个 configure 只
50
50
 
51
51
  **预设**:使用 preset 时名称固定 `clang` / `gcc`,与构建目录一致;没有 preset 时直接用上面的命令,不要两套并存。
52
52
 
53
- 下一步:target 图稳定后,进 `steps/02-modules.md` 决定哪些片段抽成函数。
53
+ 下一步:target 图稳定后,进 `02-modules.md` 决定哪些片段抽成函数。
@@ -28,10 +28,10 @@
28
28
 
29
29
  - 公开函数上方写中文 `#` 契约:一句功能、空行、边界,再用 `:param` / `:keyword` 标参数;不写 `#[[.rst:` 与 `.. command::`。
30
30
  - 完整写法见 `references/cmake.md`;签名留在 `function()` 那一行。
31
- - 签名、警告等级与错误消息以 `assets/cmake/` 和 `references/modules.md` 为准;本步不复制第二份。
31
+ - 签名、警告等级与错误消息以 `../assets/cmake/` 和 `../02-modules/01-functions.md` 为准;本步不复制第二份。
32
32
  - 普通函数只改传入 target 的属性,不写全局变量、不读环境变量、不下载依赖;唯一例外是 `LinkSettings_FetchGoogleTest`,只在测试需要时调用。
33
33
  - 先校验 target、可见性与标准,再调用 `target_*` 或 `set_target_properties`;失败用 `FATAL_ERROR`,消息带函数名与非法值。
34
34
 
35
35
  ## 退出
36
36
 
37
- 模块可被根文件导入且函数签名稳定后,进 `steps/03-check.md` 跑 configure、构建与数据库核对。排版、2 空格与注释形态按 `references/cmake.md`。
37
+ 模块可被根文件导入且函数签名稳定后,进 `03-check.md` 跑 configure、构建与数据库核对。排版、2 空格与注释形态按 `../01-targets/01-rules.md`。
@@ -30,10 +30,10 @@ GCC 模式把目录和编译器换成 `build/gcc`、`g++`。每次检查都重
30
30
  | 现象 | 回哪一步 |
31
31
  | --- | --- |
32
32
  | 找不到 target、链接失败、include 路径不对 | 第 1 步 |
33
- | 目标标准没有生效、`-std` 与声明不一致 | 第 1 步,必要时重读 `references/cxx-standard.md` |
33
+ | 目标标准没有生效、`-std` 与声明不一致 | 第 1 步,必要时重读 `../03-standard/01-cxx-standard.md` |
34
34
  | 函数参数没校验、模块重复导入、旧模块残留 | 第 2 步 |
35
35
  | 只是 CTest 或运行失败 | 转 `building-cpp` 的通过检查 |
36
36
 
37
37
  ## 交回构建
38
38
 
39
- 本步的判据是 configure 与构建成功、数据库标准正确、结构规则无命中;工具链、入口脚本、`clang-tidy` 与 CTest 的完整检查见 `building-cpp` 的 `steps/03-check.md`。
39
+ 本步的判据是 configure 与构建成功、数据库标准正确、结构规则无命中;工具链、入口脚本、`clang-tidy` 与 CTest 的完整检查见 `building-cpp` 的 `../../../building-cpp/steps/03-check.md`。
@@ -1,6 +1,6 @@
1
1
  # 测试与 CTest
2
2
 
3
- 测试属于构建域:测试 target 由 `configuring-cmake` 写进 CMake,测试代码与 CTest 运行由本技能核对。条文依据 GoogleTest Primer、CMake 的 `add_test` / `gtest_discover_tests` 文档与 CTest 手册,访问日期 2026-10-27。
3
+ 测试属于构建域:测试 target 由 `engineering` 写进 CMake,测试代码与 CTest 运行由本技能核对。条文依据 GoogleTest Primer、CMake 的 `add_test` / `gtest_discover_tests` 文档与 CTest 手册,访问日期 2026-10-27。
4
4
 
5
5
  ## 先决定测什么
6
6
 
@@ -41,10 +41,10 @@ gtest_discover_tests(tictactoe_test
41
41
 
42
42
  | 现象 | 先看 | 转到 |
43
43
  | --- | --- | --- |
44
- | 找不到测试 target 或 `gtest` | CMake 的 `enable_testing()`、`add_subdirectory(tests)`、链接目标 | `configuring-cmake` |
44
+ | 找不到测试 target 或 `gtest` | CMake 的 `enable_testing()`、`add_subdirectory(tests)`、链接目标 | `engineering` |
45
45
  | 断言失败但行为符合预期 | 测试期望是否写错、是否依赖未初始化状态 | 本文件 |
46
46
  | 断言失败且行为不对 | 被测函数的实现与契约 | `developing-cpp` |
47
- | 用例数比预期少 | `gtest_discover_tests` 的发现超时、测试是否在正确 target | 本文件与 `steps/03-check.md` |
47
+ | 用例数比预期少 | `gtest_discover_tests` 的发现超时、测试是否在正确 target | 本文件与 `../steps/03-check.md` |
48
48
  | 偶发失败 | 共享临时文件、固定端口、执行顺序依赖 | 本文件 |
49
49
 
50
50
  ## 不做什么
@@ -0,0 +1,14 @@
1
+ # clang-format
2
+
3
+ 三件语言工具各管一段:`clang-format` 排版、`clang-tidy` 诊断、`clangd` 提供补全/跳转/诊断。它们都读同一份编译数据库,但职责不重叠。编辑器侧只保留 CMake Tools 作为配置、构建、运行和调试入口;C/C++ 扩展只做 `CMake: Debug` 的调试后端,不参与语言服务。
4
+
5
+ ```bash
6
+ clang-format --dry-run --Werror src/*.cpp include/*.h tests/*.cpp
7
+ ```
8
+
9
+ - 检查用 `--dry-run --Werror`;需要自动修复时单独跑 `clang-format -i`,不要在构建脚本里悄悄改源码。
10
+ - 工程必须有根 `.clang-format`;缺失时先复制配置,不要回退到内置风格,回退会掩盖配置缺失。
11
+ - 只扫描项目源码:`src/`、`include/`、`apps/`、`tests/` 等实际存在的目录;不扫描 `build/`、第三方、生成文件。
12
+ - 配置文件在工程根 `.clang-format`;不要依赖用户主目录或编辑器内置配置。
13
+ - `BasedOnStyle: Google`、`Standard: Latest`;clang-format 21/22 不接受 `c++23`,`Latest` 按工具支持的最高标准解析。列宽、缩进与包含顺序以工程根 `.clang-format` 为准;工程显式写 `ColumnLimit` 时按工程值执行,模板资产不写 `ColumnLimit`。
14
+ - 格式化失败就是失败,不要用 `// clang-format off` 绕过;确需关闭时只包住无法排版的宏或表格,并写一句理由。
@@ -0,0 +1,51 @@
1
+ # clang-tidy 与静态检查门禁
2
+
3
+ ## clang-tidy
4
+
5
+ ```bash
6
+ clang-tidy -p build/clang \
7
+ --header-filter="^$(pwd -P)/(include|src|apps|tests)/" \
8
+ --warnings-as-errors='*' \
9
+ src/*.cpp apps/*.cpp tests/*.cpp
10
+ ```
11
+
12
+ - `-p` 指向当前编译器的构建目录,读取 `compile_commands.json`。
13
+ - `--header-filter` 控制哪些头文件的诊断被显示,不改变 clang-tidy 实际解析哪些头;模板实例化可能让一条根因产生多条警告,警告条数不等于缺陷条数。按根因修,不要按条数修。
14
+ - `--header-filter` 用项目头目录的白名单,不要用 `.*` 把系统头和第三方头一并纳入。clang-tidy 按绝对路径匹配,所以上面用 `$(pwd -P)` 前缀;上面是常见目录,工程用别的顶层目录时按实际替换。`--exclude-header-filter` 到 clang-tidy 19 才加入,16/17/18 都没有,不要依赖它。
15
+ - 系统头默认被排除,不要加 `--system-headers`。
16
+ - 只扫描项目源文件;不要把 `build/` 或第三方源码传给 clang-tidy。
17
+ - `--warnings-as-errors='*'` 把警告当失败;修代码,不要新增 `NOLINT`。确需抑制时写 `// NOLINT(检查名): 理由`,理由必须具体。
18
+ - 配置在工程根 `.clang-tidy`;默认集合是 `google-*`、`portability-avoid-pragma-once` 加 `readability-identifier-naming`(第二条去掉 `#pragma once`,与路径式守卫一致)。关闭某条时逐条写理由,不整族关闭;命名规则只配项目确实统一的项,不设 `FunctionCase`。
19
+ - 没有编译数据库时先回到 `building-cpp` 的定构建生成;不要用 `--` 手工拼编译参数绕过。
20
+ - `clang-tidy` 的诊断可能指向头文件;修头文件里的声明或实现,不要只改调用点。
21
+
22
+ ## 门禁分级
23
+
24
+ `--warnings-as-errors='*'` 是默认门禁。若项目必须把一组诊断先设为观察项,按检查名逐条写进项目脚本,不按 `*` 整族降级:
25
+
26
+ | 级别 | 典型检查 | 处理 |
27
+ | --- | --- | --- |
28
+ | 失败 | `google-*`、`readability-identifier-naming`、项目声明的致命集 | 修代码;不允许用 NOLINT 掩盖 |
29
+ | 失败 | 编译诊断、链接诊断、格式检查 | 直接失败 |
30
+ | 观察 | 迁移期暂时无法修完的个别 `google-*` 子项 | 在项目技能里列清单、写负责人和退出条件;不默认全仓关闭 |
31
+
32
+ - 致命集宁可小、可解释,也不要把所有检查一刀切。
33
+ - 观察项不是免死金牌:新代码不应新增观察项,已有项只能减少。
34
+ - 关闭某条检查时,在 `.clang-tidy` 里写一行理由,并在项目技能里记录退出条件。
35
+
36
+ ## 版本与一致性
37
+
38
+ - `clang-format` / `clang-tidy` ≥ 16;clang 模式下与 `clang++`、`clangd` 同主版本。
39
+ - 混版本常见症状:格式化结果与 CI 不同、clangd 诊断与 tidy 不一致、选项被静默忽略。
40
+ - 检查器在 `--live` 时核对版本;不要用「能跑就行」绕过。
41
+
42
+ ## 失败分诊
43
+
44
+ | 现象 | 可能原因 | 处理 |
45
+ | --- | --- | --- |
46
+ | `clang-tidy` 报找不到编译数据库 | 没 configure 或路径错 | 回到 `building-cpp` 的定构建生成 `build/<compiler>/compile_commands.json` |
47
+ | clangd 报找不到系统头 | 编译数据库里的编译器是相对路径 | 用绝对路径重新 configure,或配 `--query-driver` |
48
+ | 格式化结果与 CI 不同 | 版本不同或配置不是工程根那份 | 统一版本,确认 `.clang-format` 在工程根 |
49
+ | tidy 报系统头 | 加了 `--system-headers` 或 header-filter 过宽 | 去掉 `--system-headers`,用项目头目录白名单 |
50
+ | 大量 `readability-*` | 代码风格未统一 | 回到 `developing-cpp` 的定声明 / 定实现修声明与实现,不要批量 NOLINT |
51
+ | clangd 与 tidy 诊断不一致 | 两者读的数据库/版本不同 | 统一 `CompilationDatabase` 与工具版本 |
@@ -0,0 +1,83 @@
1
+ # clangd 与编辑器
2
+
3
+ ## clangd
4
+
5
+ `.clangd`:
6
+
7
+ ```yaml
8
+ CompileFlags:
9
+ CompilationDatabase: build/clang
10
+ Diagnostics:
11
+ Suppress:
12
+ - pp_file_not_found
13
+ ```
14
+
15
+ - `CompilationDatabase` 指向当前编译器目录;GCC 模式改 `build/gcc`。
16
+ - 不要在 `.clangd` 写 `-std`:它会覆盖 `compile_commands.json`,把 C++23 工程降成旧标准。标准只由构建声明和编译数据库决定。
17
+ - 静态检查规则只在 `.clang-tidy` 里维护;clangd 读取同一份配置,不要在这里复制检查列表。
18
+ - `Suppress` 只放确实无法避免的解析噪声(如 `pp_file_not_found`),并写理由。
19
+
20
+ `--query-driver`:
21
+
22
+ - 它是 clangd 的命令行参数,不是 `.clangd` 的 YAML 键。
23
+ - 作用:允许 clangd 执行编译器驱动,读取系统头路径;只对编译数据库里出现的驱动生效。
24
+ - 写在 `.vscode/settings.json`:
25
+
26
+ ```jsonc
27
+ {
28
+ "clangd.arguments": [
29
+ "--query-driver=/usr/bin/clang++",
30
+ "--header-insertion=never",
31
+ "--background-index"
32
+ ]
33
+ }
34
+ ```
35
+
36
+ - 路径用绝对路径;多个驱动用逗号分隔。GCC 模式指向 `/usr/bin/g++`。
37
+ - 不要写 `--query-driver=*` 或宽泛的 glob;这等于允许 clangd 执行任意匹配的驱动。
38
+ - 如果编译数据库里的编译器是相对路径,clangd 可能拒绝执行;用绝对路径重新 configure。
39
+ - `--query-driver` 只影响 clangd,不影响 clang-tidy;tidy 用编译数据库里的命令。
40
+
41
+ ## 编辑器
42
+
43
+ `.vscode/extensions.json` 推荐:
44
+
45
+ ```json
46
+ {
47
+ "recommendations": [
48
+ "llvm-vs-code-extensions.vscode-clangd",
49
+ "ms-vscode.cmake-tools",
50
+ "ms-vscode.cpptools"
51
+ ]
52
+ }
53
+ ```
54
+
55
+ `.vscode/settings.json` 固定:
56
+
57
+ ```jsonc
58
+ {
59
+ "clangd.arguments": [
60
+ "--query-driver=/usr/bin/clang++",
61
+ "--header-insertion=never",
62
+ "--background-index"
63
+ ],
64
+ "cmake.buildDirectory": "${workspaceFolder}/build/clang",
65
+ "cmake.generator": "Ninja",
66
+ "cmake.buildBeforeRun": true,
67
+ "cmake.exportCompileCommandsFile": true,
68
+ "cmake.debugConfig": {
69
+ "type": "cppdbg",
70
+ "request": "launch",
71
+ "MIMode": "lldb",
72
+ "miDebuggerPath": "/usr/bin/lldb",
73
+ "stopAtEntry": false
74
+ },
75
+ "C_Cpp.intelliSenseEngine": "disabled"
76
+ }
77
+ ```
78
+
79
+ - 配置、构建、运行和调试只从 CMake Tools 进入;不要同时维护 `tasks.json` 或 `launch.json`,否则会出现第二套构建或启动路径。
80
+ - C/C++ 扩展只作为 CMake 快速调试的 `cppdbg` 后端;IntelliSense 关闭,补全、跳转、诊断和格式化只由 clangd 提供。
81
+ - 不推荐与 clangd 冲突的 C++ 智能提示插件;只保留一个语言服务。
82
+ - 不把 `compile_commands.json` 提交进仓库;它是构建产物。
83
+ - 切换编译器时同时改 `.clangd`、`settings.json` 和构建目录;三处不一致会让诊断指向旧代码。GCC 模式把 `MIMode` 改为 `gdb`、`miDebuggerPath` 改为 `/usr/bin/gdb`。
@@ -0,0 +1,17 @@
1
+ # 正反例:clang-format
2
+
3
+ ## 构建脚本里自动格式化
4
+
5
+ **差**:
6
+
7
+ ```bash
8
+ clang-format -i src/*.cpp # 构建时悄悄改源码
9
+ ```
10
+
11
+ **好**:
12
+
13
+ ```bash
14
+ clang-format --dry-run --Werror "${sources[@]}" # 只检查
15
+ ```
16
+
17
+ 需要自动修复时单独运行 `clang-format -i`,由人确认 diff。