docs: update VDE-016 — using declarations are no-ops inside same namespace; only fully-qualified names work
This commit is contained in:
+30
-48
@@ -1,6 +1,6 @@
|
||||
---
|
||||
id: VDE-016
|
||||
status: fixed
|
||||
status: open
|
||||
severity: critical
|
||||
category: bug
|
||||
date: 2026-07-27
|
||||
@@ -9,63 +9,45 @@ reporter: ViewDesign
|
||||
related: VDE-001, VDE-005, VDE-010
|
||||
---
|
||||
|
||||
# VDE-016: ssi_boolean.cpp 名称解析 — using 声明位置错误
|
||||
# VDE-016: ssi_boolean.cpp GCC 名称查找失败(using 声明无效)
|
||||
|
||||
## 问题描述
|
||||
|
||||
v1.0.4 在匿名 namespace **内部**(line 57)添加了 `using vde::brep::SSICurveData;`,但这些 using 声明仅在匿名 namespace 内部有效。匿名 namespace 关闭后,后续的公共函数(line 509+)仍然找不到 `SSICurveData` 和 `ClassResult`。
|
||||
在 `vde::brep` 作用域内使用 `using vde::brep::SSICurveData;` 和 `using vde::brep::ClassResult;` 是空操作,GCC 忽略。匿名 namespace 关闭后的公共函数仍找不到这些类型。
|
||||
|
||||
## 编译错误 (v1.0.4)
|
||||
已尝试的方案及其结果:
|
||||
|
||||
| 方案 | 代码 | 结果 |
|
||||
|------|------|:--:|
|
||||
| v1.0.4 | `using` 放在 `namespace{` 内部 | 仅匿名 ns 内有效,关闭后失效 |
|
||||
| v1.0.5 | `using ClassResult;` / `using SSICurveData;` | 语法错误:expected nested-name-specifier |
|
||||
| 修正语法 | `using vde::brep::ClassResult;` / `using vde::brep::SSICurveData;` | 空操作,GCC 忽略 |
|
||||
| 全限定名 | `vde::brep::SSICurveData` / `vde::brep::ClassResult` | 类型找到,但级联问题(enum值/mesh) |
|
||||
|
||||
## 编译错误 (v1.0.5, 无 workaround)
|
||||
|
||||
```
|
||||
error: 'SSICurveData' was not declared in this scope
|
||||
at line 512 (compute_all_ssi return type)
|
||||
error: 'ClassResult' was not declared in this scope
|
||||
at line 646 (classify_points return type)
|
||||
error: 'begin'/'end' was not declared in this scope (级联失败)
|
||||
error: 'SSICurveData' was not declared at lines 510, 613
|
||||
error: 'begin'/'end' was not declared (级联)
|
||||
error: 'ClassResult' was not declared at line 644
|
||||
```
|
||||
|
||||
## 唯一可用的修复方案:全限定名
|
||||
|
||||
**已验证可行**:将所有非限定名替换为全限定名:
|
||||
|
||||
```
|
||||
SSICurveData → vde::brep::SSICurveData
|
||||
ClassResult → vde::brep::ClassResult
|
||||
OUT / IN → vde::brep::OUT / vde::brep::IN (enum values)
|
||||
mesh → vde::mesh (namespace)
|
||||
```
|
||||
|
||||
代码量较大(~20+ 处),但有效。
|
||||
|
||||
## 根因
|
||||
|
||||
```cpp
|
||||
// ssi_boolean.cpp 当前结构
|
||||
namespace vde::brep { // line 34
|
||||
struct SSICurveData; // line 43
|
||||
using vde::brep::ClassResult; // line 44 — 自引用,无效
|
||||
struct SSICurveData { ... }; // line 47
|
||||
|
||||
namespace { // line 56
|
||||
using vde::brep::SSICurveData; // ← 仅在匿名 ns 内有效!
|
||||
using vde::brep::ClassResult; // ← 同上
|
||||
...
|
||||
} // line 92 或 432 关闭
|
||||
|
||||
// 以下公共函数在 vde::brep 作用域,using 声明已失效
|
||||
std::vector<SSICurveData> compute_all_ssi(...) { // ← 找不到
|
||||
std::vector<...ClassResult> classify_points(...) { // ← 找不到
|
||||
}
|
||||
```
|
||||
|
||||
## 正确修复
|
||||
|
||||
将 using 声明放在 `vde::brep` 作用域(匿名 namespace 之外):
|
||||
|
||||
```cpp
|
||||
namespace vde::brep {
|
||||
struct SSICurveData;
|
||||
using SSICurveData; // ← 放在这里(vde::brep 级别)
|
||||
using ClassResult; // ← 替代自引用的 using vde::brep::ClassResult;
|
||||
struct SSICurveData { ... };
|
||||
|
||||
namespace {
|
||||
// 不需要这里的 using 了
|
||||
...
|
||||
}
|
||||
|
||||
// 公共函数现在可以找到 SSICurveData 和 ClassResult
|
||||
std::vector<SSICurveData> compute_all_ssi(...) { ... }
|
||||
}
|
||||
```
|
||||
GCC 两阶段查找对此文件的 namespace 嵌套结构处理与 MSVC 不同。即使在同一个 `vde::brep` namespace 中,`#include` 引入的类型 + 局部前向声明 + 多个匿名 namespace 的组合导致 GCC 在第二遍查找(非限定名)时找不到同命名空间的符号。
|
||||
|
||||
## 当前 Workaround
|
||||
|
||||
|
||||
Reference in New Issue
Block a user