Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report diagnostic error on user interface #300

Open
1 of 2 tasks
yanminhui opened this issue May 31, 2023 · 1 comment
Open
1 of 2 tasks

Report diagnostic error on user interface #300

yanminhui opened this issue May 31, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@yanminhui
Copy link

yanminhui commented May 31, 2023

Search before asking

  • I searched the issues and found no similar issues.

What happened + What you expected to happen

#include <struct_pack/struct_pack.hpp>

struct person {
  int age;
  std::string name;
  person() = default;
};

template <class T>
requires std::is_aggregate_v<T>
void serialize(T&& t) {
    auto _ = struct_pack::serialize(std::forward<T>(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.

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<struct_pack::detail::memory_writer, person>::calculate_hash_head<{0}, person>' is not a constant expression
    constexpr auto hash_head = calculate_hash_head<conf, T, Args...>() |
                               ^
/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<conf, T, Args...>() |
                   ^
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:

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<person>' evaluated to false
requires std::is_aggregate_v<T>
         ^
1 error generated.

Reproduction way

Anything else

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!
@poor-circle
Copy link
Collaborator

Well, We are trying to add some method so that struct_pack could support non-aggregate-type. But you are right, there are too many error now, and we should add some concept to simply the compile error output.

@poor-circle poor-circle added the enhancement New feature or request label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants