已开启
GE定向“质量加固”社区有奖任务 #517
夏国正创建于  20 天前
夏国正成员
20 天前 创建

"质量加固"社区活动有奖活动

一、任务背景

为进一步提升CANN开源社区代码质量,引导开发者关注代码规范与最佳实践,激发社区代码审查与优化活力,特举办"质量加固"有奖活动。通过设定明确的代码检查规则,鼓励开发者主动发现并修复社区仓库中不符合编码规范的代码问题,帮助开发者提升C++编码素养,推动CANN开源项目代码质量持续提升。

二、活动规则

2.1 编码规范规则和提交代码规范

规则编号 规则名称 规则说明
规则1 成员函数const修饰 不会修改成员变量的成员函数应使用const修饰
规则2 参数const修饰 指针和引用类型的参数,如不需修改其引用对象,应使用const修饰
规则3 不可变数据声明 constexpr或const说明符应用于不可变数据声明
规则4 参数名一致性 函数的所有声明必须与定义具有一致的参数名
规则5 无用头文件清理 禁止包含用不到的头文件
规则6 头文件自包含 头文件应该自包含,不需使用者额外引入依赖
规则7 枚举类优先 优先使用枚举类(enum class)而不是普通枚举(enum)
规则8 不可执行代码路径 项目中不应包含不可执行的代码路径
规则9 lambda捕获模式 避免lambda表达式使用默认捕获模式([=]或[&])
  1. 在ge社区仓库代码中,找到10条及以上符合上述9项规则或者其他规则的代码问题:
  2. 按照规则完成代码修复
  3. 提交PR,PR标题中标记 【质量加固】 作为前缀
  4. 获奖通知方式:请在pr合入后添加小助手微信,具体获奖信息将在2026.9.30左右收集
    GE小助手二维码.jpg

2.2 获奖条件

  1. 该GitCode ID暂未在CANN社区仓合入过PR(面向新贡献者)
  2. 提交的PR符合上述条件并被成功合入

2.3 获奖范围

  • 前10位成功合入PR的GitCode ID
  • 如多个GitCode ID确认为同一人,则不重复获奖
  • 同一个GitCode ID成功合入多个PR,也不重复获奖
  • 活动时间2026.8.1-2026.9.30

2.4 奖品

Huawei手环 11NFC款

三、验收标准

获奖排名:前10位成功合入PR的GitCode ID按合入时间先后排序,依次获得奖品。


附录:代码检查规则详细示例

规则1:成员函数const修饰

错误示例:

class Foo {
public:
    void PrintValue()
    {
        std::cout << value;
    }
    int GetValue()
    {
        return value;
    }
private:
    int value;
};

正确修复示例:

class Foo {
public:
    void PrintValue() const
    {
        std::cout << value;
    }
    int GetValue() const
    {
        return value;
    }
private:
    int value;
};

规则2:指针/引用参数const修饰

错误示例:

void Log(int32_t &val)
{
    std::cout << "val = " << val << std::endl;
}

void myfunc(int16_t *param1, const int16_t *param2,
            int16_t *param3, int16_t *const param4)
{
    *param1 = *param2 + *param3 + *param4;
}

正确修复示例:

void Log(const int32_t &val)
{
    std::cout << "val = " << val << std::endl;
}

void myfunc(int16_t *param1, const int16_t *param2,
            const int16_t *param3, const int16_t *const param4)
{
    *param1 = *param2 + *param3 + *param4;
}

规则3:constexpr/const不可变数据声明

错误示例:

void Fn()
{
    std::int16_t x3 = 5; // x3未被修改,但未声明为常量
}

正确修复示例:

void Fn()
{
    const std::int16_t x1 = 5;
    constexpr std::int16_t x2 = 5;
}

规则4:函数声明与定义参数名一致性

错误示例:

// Fun.h
void Fun1(int);
void Fun2(int count, int num);
// Fun.c
void Fun1(int num) { ... }
void Fun2(int num, int count) { ... }

正确修复示例:

// Fun.h
void Fun1(int num);
void Fun2(int num, int count);
// Fun.c
void Fun1(int num) { ... }
void Fun2(int num, int count) { ... }

规则5:禁止包含无用头文件

错误示例:

#include "func.h"
int Foo(int a, int b)
{
    return a + b;
}

正确修复示例:

int Foo(int a, int b)
{
    return a + b;
}

规则6:头文件自包含

错误示例:

#ifndef DEBUG_FUNC_H
#define DEBUG_FUNC_H
#define DEBUG_FUNC_START printf("FUNC:[%s] start\n", __func__)
#endif

正确修复示例:

#ifndef DEBUG_FUNC_H
#define DEBUG_FUNC_H
#include <stdio.h>
#define DEBUG_FUNC_START printf("FUNC:[%s] start\n", __func__)
#endif

规则7:优先使用枚举类

错误示例:

enum State { DEFAULT, RUNNING, STOP };
constexpr int DEFAULT = 1; // 编译错误:重复声明

正确修复示例:

enum class State { DEFAULT, RUNNING, STOP };
constexpr int DEFAULT = 1;

规则8:不可执行代码路径

错误示例:

void infeas(uint8_t para, uint8_t outp)
{
    if (para >= 0U) {
        outp = 1U;
    }
}

正确修复示例:

void infeas(uint8_t para, uint8_t outp)
{
    if (outp == 1U) {
        outp = 0U;
    }
}

规则9:lambda避免默认捕获模式

错误示例:

auto lambda = [=]() { data += value; };       // 默认按值捕获
auto lambda = [&]() { std::cout << *p << endl; }; // 默认按引用捕获

正确修复示例:

auto lambda = [value, this]() { data += value; };
auto lambda = [value = *p]() { std::cout << value << endl; };
likedislike
夏国正成员
20 天前 修改了issue 的描述
此处折叠了9条事件消息 查看更多
QQWH789456
12 天前 关联了pull request:【质量加固】补充成员函数与不可变数据的 const 修饰
QWH789456
12 天前 评论:

已提交质量加固 PR:https://gitcode.com/cann/ge/merge_requests/4493 (仅 const 相关规则1/2/3,共10处)

likedislike
QQWH789456
11 天前 关联了pull request:【质量加固】补充成员函数与不可变数据的 const 修饰
FieeFiee
10 天前 关联了pull request:【质量加固】修复若干符合编码规范规则和提交代码规范的问题
Wwxh456
10 天前 关联了pull request:【质量加固】补充成员函数与不可变数据的 const 修饰
wxh456
10 天前 评论:

已提交质量加固 PR(develop,仅 const 相关 10 处):https://gitcode.com/cann/ge/merge_requests/4511

likedislike
Fiee
Fiee
6 天前 评论:

GE定向“质量加固”社区有奖任务;https://gitcode.com/cann/ge/pull/4497

likedislike
夏国正成员
6 天前 删除了关联的pull request:【质量加固】修复若干符合编码规范规则和提交代码规范的问题
此处折叠了6条事件消息 查看更多
Wwxh456
5 天前 关联了pull request:【质量加固】为只读成员函数补充 const 修饰
wxh456
5 天前 评论:

已提交质量加固 PR(develop,仅 const 规则1 共10处,与既有 PR 不重复):https://gitcode.com/cann/ge/merge_requests/4597

likedislike
Wwys222111
5 天前 关联了pull request:【质量加固】修复若干符合修复规则一和规则二的若干问题的代码问题
wys222111
5 天前 评论:

GE定向“质量加固”社区有奖任务;https://gitcode.com/cann/ge/pull/4594

likedislike
夏国正成员
5 天前 删除了关联的pull request:【质量加固】补充成员函数与不可变数据的 const 修饰
Qqoosong
5 天前 关联了pull request:【质量加固】补充成员函数 const 修饰以符合编码规范(#517)
夏国正成员
5 天前 修改了issue 的描述
夏国正成员
5 天前 关联了pull request:【质量加固】补充 const 修饰、参数 const 修饰与 lambda 显式捕获
WWXQ123123
5 天前 关联了pull request:【质量加固】为只读成员函数补充 const 修饰
cnsd_turtlecnsd_turtle
4 天前 关联了pull request:【质量加固】补充 const 修饰、参数 const 修饰
cnsd_turtle
cnsd_turtle
4 天前 评论:

GE定向“质量加固”社区有奖任务;https://gitcode.com/cann/ge/pull/4611

likedislike
海洋504海洋504
4 天前 关联了pull request:【质量加固】修改若干符合代码规范的问题
海洋504
海洋504
4 天前 评论:

GE定向“质量加固”社区有奖任务;https://gitcode.com/cann/ge/pull/4618

likedislike
夏国正成员
4 天前 关联了pull request:【质量加固】修复 lambda 默认捕获与成员函数缺少 const 修饰问题
夏国正成员
4 天前 修改了issue 的描述
夏国正成员
4 天前 修改了issue 的描述
qoosong
2 天前 评论:

GE定向“质量加固”社区有奖任务; https://gitcode.com/cann/ge/pull/4608

likedislike
Zzlp1703
2 天前 关联了pull request:【质量加固】修改若干符合规则要求的代码规范问题
zlp1703
1 天前 评论:

GE定向“质量加固”社区有奖任务;https://gitcode.com/cann/ge/pull/4639

likedislike
zhaoshiyuanzhaoshiyuan
1 天前 关联了pull request:【质量加固】补充成员函数与参数的const修饰