alibaba / alibaba/yalantinglibs
Report diagnostic error on user interface
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 327
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 2
Description
### Search before asking
- [x] I searched the [issues](https://github.com/alibaba/yalantinglibs/issues) and found no similar issues.
### What happened + What you expected to happen
```.cpp
#include
struct person {
int age;
std::string name;
person() = default;
};
template
requires std::is_aggregate_v
void serialize(T&& t) {
auto _ = struct_pack::serialize(std::forward(t));
}
int main() {
#if defined(DIAGNOSTIC_REQUIRED)
serialize(person{});
#else
auto _ = struct_pack::serialize(person{});
#endif
}
```
It will produce too many error informations occupying the entire screen, and user may be can't understand.
```.shell
admin@bryan-mbam2 yltexample % clang++ -std=c++20 main.cpp -I ~/repos/yalantinglibs/include
In file included from main.cpp:1:
In file included from /Users/admin/repos/yalantinglibs/include/struct_pack/struct_pack.hpp:22:
In file included from /Users/admin/repos/yalantinglibs/include/struct_pack/struct_pack/struct_pack_impl.hpp:41:
/Users/admin/repos/yalantinglibs/include/struct_pack/struct_pack/reflection.hpp:459:7: error: static_assert failed due to requirement '!sizeof(person)' "empty struct/class is not allowed!"
static_assert(!sizeof(type), "empty struct/class is not allowed!");
^ ~~~~~~~~~~~~~
... 省略编译错误信息 ...
/Users/admin/repos/yalantinglibs/include/struct_pack/struct_pack/struct_pack_impl.hpp:1640:32: error: call to consteval function 'struct_pack::detail::packer::calculate_hash_head<{0}, person>' is not a constant expression
constexpr auto hash_head = calculate_hash_head() |
^
/Users/admin/repos/yalantinglibs/include/struct_pack/struct_pack/struct_pack_impl.hpp:1643:19: error: constexpr if condition is not a constant expression
if constexpr (hash_head % 2) { // has more metainfo
^~~~~~~~~~~~~
/Users/admin/repos/yalantinglibs/include/struct_pack/struct_pack/struct_pack_impl.hpp:1643:19: note: initializer of 'hash_head' is not a constant expression
/Users/admin/repos/yalantinglibs/include/struct_pack/struct_pack/struct_pack_impl.hpp:1640:20: note: declared here
constexpr auto hash_head = calculate_hash_head() |
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
```
Report diagnostic errors on user interfaces would be better for user, for example:
```.shell
admin@bryan-mbam2 yltexample % clang++ -std=c++20 main.cpp -I ~/repos/yalantinglibs/include -DDIAGNOSTIC_REQUIRED
main.cpp:17:5: error: no matching function for call to 'serialize'
serialize(person{});
^~~~~~~~~
main.cpp:11:6: note: candidate template ignored: constraints not satisfied [with T = person]
void serialize(T&& t) {
^
main.cpp:10:10: note: because 'std::is_aggregate_v' evaluated to false
requires std::is_aggregate_v
^
1 error generated.
```
### Reproduction way
### Anything else
### Are you willing to submit a PR?
- [ ] Yes I am willing to submit a PR!
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the diagnostics with the C++20 command shown in the issue, then inspect include/struct_pack/struct_pack/reflection.hpp and include/struct_pack/struct_pack/struct_pack_impl.hpp, where the reported errors originate. Compare the normal serialize(person{}) call with the DIAGNOSTIC_REQUIRED example; done means invalid input produces a concise, user-facing diagnostic instead of the cascading errors shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100