Skip to content

fix: fix ODR violation of PaintWidget by wrapping it in anonymous nam…#435

Merged
Ivy233 merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/PaintWidget-ODR-violation-BUG366487
Jun 16, 2026
Merged

fix: fix ODR violation of PaintWidget by wrapping it in anonymous nam…#435
Ivy233 merged 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/PaintWidget-ODR-violation-BUG366487

Conversation

@Ivy233

@Ivy233 Ivy233 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

…espace

Wrap PaintWidget class in namespace { ... } across 6 test files to comply with the C++ One Definition Rule, eliminating cppcheck ctuOneDefinitionRuleViolation errors.

fix: 用匿名命名空间修复 PaintWidget 的 ODR 违规

在 6 个测试文件中将 PaintWidget 类放入匿名命名空间,遵循 C++ 单一定义
规则,消除 cppcheck 报告的 CTU ODR 违规错误。

Log: Fix ODR violation of PaintWidget in test files by wrapping with anonymous namespace

PMS: BUG-366487

…espace

Wrap PaintWidget class in `namespace { ... }` across 6 test files to
comply with the C++ One Definition Rule, eliminating cppcheck
ctuOneDefinitionRuleViolation errors.

fix: 用匿名命名空间修复 PaintWidget 的 ODR 违规

在 6 个测试文件中将 PaintWidget 类放入匿名命名空间,遵循 C++ 单一定义
规则,消除 cppcheck 报告的 CTU ODR 违规错误。

Log: Fix ODR violation of PaintWidget in test files by wrapping with anonymous namespace

PMS: BUG-366487

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Ivy233, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review


★ 总体评分:100分

■ 【总体评价】

代码实现了测试辅助类的匿名命名空间包裹与版权信息更新,完全符合C++规范
逻辑正确且无任何安全漏洞,得满分

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

匿名命名空间的引入在C++标准中完全合法,能够正确赋予类内部链接性,解决跨翻译单元的ODR违规问题,无编译错误或内存风险
潜在问题:无
建议:保持当前写法

  • 2.代码质量(优秀)✓

将同名辅助类PaintWidget包裹在匿名命名空间中是极佳的C++实践,彻底消除了不同测试文件间的命名冲突隐患,版权年份更新及时准确
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

匿名命名空间仅在编译期起作用,不会增加任何运行时开销,不影响测试执行效率
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次改动仅涉及测试辅助类的命名空间调整与版权声明更新,不涉及任何业务逻辑、输入处理或权限控制,无安全风险

  • 建议:无

■ 【改进建议代码示例】

// 当前改动已为最佳实践,以下为符合规范的匿名命名空间包裹示例
diff --git a/dde-osd/tests/ut_audioprovider.cpp b/dde-osd/tests/ut_audioprovider.cpp
--- a/dde-osd/tests/ut_audioprovider.cpp
+++ b/dde-osd/tests/ut_audioprovider.cpp
@@ -17,6 +17,7 @@ class UT_AudioProvider : public testing::Test
 
 };
 
+namespace {
 class PaintWidget : public QWidget
 {
 
@@ -39,6 +40,7 @@ class PaintWidget : public QWidget
 public:
     AudioProvider *m_provider;
 };
+}  // namespace

@Ivy233 Ivy233 requested a review from yixinshark June 16, 2026 07:31
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ivy233, yixinshark

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Ivy233 Ivy233 merged commit edb08dc into linuxdeepin:master Jun 16, 2026
19 checks passed
@Ivy233 Ivy233 deleted the fix/PaintWidget-ODR-violation-BUG366487 branch June 16, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants