In file included from /data/gerrit/workspace_AIBox_repo/AICore/IC_NM_DataProvide...
🚨 错误信息
In file included from /data/gerrit/workspace_AIBox_repo/AICore/IC_NM_DataProvider/data_provider/src/DataProviderHelper.cpp:12:
/data/gerrit/workspace_AIBox_repo/AICore/IC_NM_DataProvider/data_provider/src/DataProviderHelper.cpp: In static member function ‘static time_t senseauto::data_provider::DataProviderHelper::StringToDataTime(const string&)’:
/data/gerrit/workspace_AIBox_repo/AICore/IC_NM_DataProvider/data_provider/include/private/log/logger.h:66:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 6 has type ‘char*’ [-Wformat=]
66 | printf("%s.%03d %s: " LOG_TAG ": " fmt "\n", timestamp, (int)milliseconds, level_str, ##__VA_ARGS__); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/data/gerrit/workspace_AIBox_repo/AICore/IC_NM_DataProvider/data_provider/include/private/log/logger.h:71:28: note: in expansion of macro ‘LOG_PRINT’
71 | #define LOGD(fmt, ...) LOG_PRINT(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
| ^~~~~~~~~
/data/gerrit/workspace_AIBox_repo/AICore/IC_NM_DataProvider/data_provider/src/DataProviderHelper.cpp:76:5: note: in expansion of macro ‘LOGD’
76 | LOGD("*****StringToDataTime(%s) => %lld\n", timeStr.c_str(), timestamp);
| ^~~~
/data/gerrit/workspace_AIBox_repo/AICore/IC_NM_DataProvider/data_provider/src/DataProviderHelper.cpp:76:43: note: format string is defined here
76 | LOGD("*****StringToDataTime(%s) => %lld\n", timeStr.c_str(), timestamp);
| ~~~^
| |
| long long int
| %s
🤖 AI解决方案
报错分析报告
1. 错误翻译
原文:format '%lld' expects argument of type 'long long int', but argument 6 has type 'char*'
译文:格式符'%lld'期望参数类型为'long long int',但实际第6个参数的类型是'char*'
2. 原因分析
根本原因:格式化字符串中的格式说明符与实际参数类型不匹配。具体位置:
- 文件:
DataProviderHelper.cpp第76行 - 宏调用:
LOGD("*StringToDataTime(%s) => %lld\n", timeStr.c_str(), timestamp); - 实际错误发生在
logger.h第66行的LOG_PRINT宏中
问题分析:编译器检测到第6个参数(在预处理展开后)的类型是char*,但格式字符串中对应的%lld期望的是long long int类型。
3. 解决方案
// 修复后的代码 - DataProviderHelper.cpp 第76行
LOGD("*****StringToDataTime(%s) => %ld\n", timeStr.c_str(), (long)timestamp);
或者根据timestamp的实际类型选择正确的格式符:
// 选项1:如果timestamp是time_t类型(通常为long)
LOGD("*****StringToDataTime(%s) => %ld\n", timeStr.c_str(), timestamp);
// 选项2:如果timestamp是64位整数
LOGD("*****StringToDataTime(%s) => %lld\n", timeStr.c_str(), (long long)timestamp);
// 选项3:使用更安全的C++方式
LOGD("*****StringToDataTime(%s) => %zu\n", timeStr.c_str(), static_cast<size_t>(timestamp));
4. ️ 预防措施
最佳实践建议:
-Wformat警告开启,这是发现格式化错误的有效手段检查清单:
-Wall -Wextra标志%zu或进行显式类型转换---
修复关键:确保格式说明符%lld、%ld、%zu等与对应的参数类型严格匹配。