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

piping tuple into a test case enforces const-ness of passed type instances #598

Open
ambushed opened this issue Dec 8, 2023 · 0 comments

Comments

@ambushed
Copy link
Contributor

ambushed commented Dec 8, 2023

Expected Behavior

I would like to be able to call non-const methods on a tuple member, i.e. the code below should compile:

struct Type1 {
    int get_num_const() const {return 1;}
    int get_num() {return 1;} 
};

int main() {
  using namespace boost::ut;

  "types"_test =
      []<class T>(T& t) {
        expect(that% t.get_num() == 2) << reflection::type_name<T>() << "failed the test"; // "Type1" failed the test.
      } | std::tuple{Type1{}};
}

Actual Behavior

Instead, I am getting a compile error:

<source>:19:31: error: passing 'const Type1' as 'this' argument discards qualifiers [-fpermissive]
   19 |         expect(that% t.get_num() == 2) << reflection::type_name<T>() << "failed the test";
      |                      ~~~~~~~~~^~
<source>:10:9: note:   in call to 'int Type1::get_num()'
   10 |     int get_num() {return 1;}
      |         ^~~~~~~

At the moment, i am forced to hack the const modifier away (e.g.: auto* t1 = const_cast<std::remove_const<T>::type*>(&t))

Looking at the ut internals, the issue can be "fixed" by removing const modifier of the arg parameter in the following line

static constexpr auto run_impl(T test, const TArg& arg)

and let the user decide whether the param is being passed as a const reference or a mutable one?

Steps to Reproduce the Problem

  1. See the godbolt link

Specifications

  • Version: master
  • Platform: macOS m1
  • Subsystem: clang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant