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

Using etl::make_vector to make a vector of two pairs causes a compile error #931

Closed
relativityspace-jsmith opened this issue Jul 22, 2024 · 1 comment

Comments

@relativityspace-jsmith
Copy link

relativityspace-jsmith commented Jul 22, 2024

I noticed something odd today when trying to use etl::make_vector. This works:

auto foo = etl::make_vector(
    etl::make_pair("foo", 1),
    etl::make_pair("bar", 2),
    etl::make_pair("baz", 3)
);

but this doesn't

auto foo = etl::make_vector(
    etl::make_pair("foo", 1),
    etl::make_pair("bar", 2)
//    etl::make_pair("baz", 3)
);

(even though it's just commenting out one of the entries).

The compile error looks like:

C:/REDACTED/ext/etl/include/etl/utility.h: In instantiation of 'constexpr etl::pair<T1, T2>::pair(U1&&, U2&&) [with U1 = etl::pair<const char (&)[4], int>; U2 = etl::pair<const char (&)[4], int>; T1 = const char (&)[4]; T2 = int]':
C:/REDACTED/ext/etl/include/etl/vector.h:1363:40:   required from 'constexpr etl::vector<typename etl::common_type< <template-parameter-1-1> >::type, sizeof... (T)> etl::make_vector(T&& ...) [with T = {pair<const char (&)[4], int>, pair<const char (&)[4], int>}; typename common_type< <template-parameter-1-1> >::type = pair<const char (&)[4], int>]'
<the code snippet I pasted>:   required from here
C:/REDACTED/ext/etl/include/etl/utility.h:138:9: error: invalid initialization of reference of type 'const char (&)[4]' from expression of type 'etl::pair<const char (&)[4], int>'
  138 |       : first(etl::forward<U1>(a))
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
C:/REDACTED/ext/etl/include/etl/utility.h:139:9: error: cannot convert 'etl::pair<const char (&)[4], int>' to 'int' in initialization
  139 |       , second(etl::forward<U2>(b))
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~

I think it has something to do with how etl::make_vector is defined:

  template <typename... T>
  constexpr auto make_vector(T&&... t) -> etl::vector<typename etl::common_type_t<T...>, sizeof...(T)>
  {
    return { { etl::forward<T>(t)... } };
  }

I think that, if the parameter pack etl::forward<T>(t)... expands to exactly two elements, it treats { etl::forward<T>(t)... } as the initializer for a pair type, and then tries to call etl::pair<const char *, int>() passing each of the two pairs as the two constructor arguments. Unfortunately, I don't really understand why it's doing this or how to fix it. Hopefully you have some insight!

Chiraffollo added a commit to Chiraffollo/etl that referenced this issue Jul 23, 2024
Superfluous curly braces removed
jwellbelove pushed a commit that referenced this issue Jul 23, 2024
* Fix doc comment for pool::allocate() (#914)

* Fix issue #931

Superfluous curly braces removed

---------

Co-authored-by: Michael K <[email protected]>
@multiplemonomials
Copy link

Thanks for the quick fix!

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

3 participants