已开启
GE定向“质量加固”社区有奖任务 #517
夏国正创建于 20 天前
此处折叠了9条事件消息 查看更多
QWH789456
12 天前 评论:
12 天前 评论:
已提交质量加固 PR:https://gitcode.com/cann/ge/merge_requests/4493 (仅 const 相关规则1/2/3,共10处)


10 天前 关联了pull request:【质量加固】修复若干符合编码规范规则和提交代码规范的问题
wxh456
10 天前 评论:
10 天前 评论:
已提交质量加固 PR(develop,仅 const 相关 10 处):https://gitcode.com/cann/ge/merge_requests/4511


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


此处折叠了6条事件消息 查看更多
wxh456
5 天前 评论:
5 天前 评论:
已提交质量加固 PR(develop,仅 const 规则1 共10处,与既有 PR 不重复):https://gitcode.com/cann/ge/merge_requests/4597


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


4 天前 关联了pull request:【质量加固】补充 const 修饰、参数 const 修饰
cnsd_turtle
4 天前 评论:
4 天前 评论:
GE定向“质量加固”社区有奖任务;https://gitcode.com/cann/ge/pull/4611


4 天前 关联了pull request:【质量加固】修改若干符合代码规范的问题
海洋504
4 天前 评论:
4 天前 评论:
GE定向“质量加固”社区有奖任务;https://gitcode.com/cann/ge/pull/4618


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


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


1 天前 关联了pull request:【质量加固】补充成员函数与参数的const修饰
"质量加固"社区活动有奖活动
一、任务背景
为进一步提升CANN开源社区代码质量,引导开发者关注代码规范与最佳实践,激发社区代码审查与优化活力,特举办"质量加固"有奖活动。通过设定明确的代码检查规则,鼓励开发者主动发现并修复社区仓库中不符合编码规范的代码问题,帮助开发者提升C++编码素养,推动CANN开源项目代码质量持续提升。
二、活动规则
2.1 编码规范规则和提交代码规范
2.2 获奖条件
2.3 获奖范围
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; };