rollbear/strong_type

I solved the error that occurred when using the -std=c++20 flag, but I'm not sure if it's the right thing to do. Indirection requires pointer operand ('size_type' (aka 'unsigned long') invalid)clang(typecheck_indirection_requires_pointer)

SilmaliTech opened this issue · 6 comments

example

#include <vector>
#include <iostream>
int main() {
  #define OPERATORS strong::arithmetic, strong::ordered, strong::equality, strong::incrementable, strong::pointer, strong::iostreamable, strong::unique, strong::convertible_to<std::string>, strong::implicitly_convertible_to<std::string>
  
  using aaaaaaaaa = strong::type<double, struct aaaaaaaaa_, OPERATORS>;
  
  std::vector<aaaaaaaaa> bb;
  if (bb.size() == 0) {
      std::cout << "eorrrrrrr" << std::endl;
  }
}

Compile with commands such as g++13 -std=c++20 =Wall -Werror -pthread.
If you change to -std=c++17, the error will not occur....

In the above code, an error such as Indirection requires pointer operand ('size_type' (aka 'unsigned long') invalid)clang(typecheck_indirection_requires_pointer) occurs.

To resolve this error, you need to remove the "*" keyword from pointer.hpp.
Then the error will disappear.

  1. line 90
    original decltype(*std::declval<const T&>())
    Modify decltype(std::declval<const T&>())
  2. line 100
    original decltype(&(*std::declval<const T&>())) operator->() const { return &operator*();}
    Modify decltype(&(std::declval<const T&>())) operator->() const { return &operator*();}

If you fix it like this, the error itself won't occur, but I'm not sure if it works properly...

This is very interesting. Thank you for reporting. I will have a look. The CI pipeline builds with, amongst many others, g++13 -std=c++20 -Wall -Wextra -Wconversion -pedantic -Werror without issue, so your case is surprising.

Wait, you do realize that the type you're trying to make is completely bonkers and doesn't make any sense what so ever? It's a floating point number, but you want to be able to use it as a pointer and to both implicitly and explicitly convert it to std::string. What would you expect of such a type?

What I can do is to try to make the compilers give you better messages that explains why the cannot possibly ever work.

Do note what the docs say:

  • strong::convertible_to<Ts...> provides an explicit operator Ts() const for each type Ts, providing the underlying type supports it.
  • strong::pointer allows operator* and operator->, and comparisons with nullptr providing the underlying type supports it.

The underlying type double supports none of those.

Sorry... I'd like to make an excuse that I'm a C++ beginner... I feel like I'm dying of embarrassment...

No worries. It takes time to learn. I will make the improvements to the compilation error messages to make the next beginner a little less confused.

And thank you for bringing this deficiency to my attention.

Thank you. I want to study hard and have good skills!!