ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.05k stars 373 forks source link

[porting] IAR's overload resolution struggles with `etl::span::span(etl::array&)` #753

Closed dhebbeker closed 9 months ago

dhebbeker commented 10 months ago

I try to construct a etl::span from an etl::array. This shouldn't be any issue as an appropriate constructor exists.

I have an example on Compiler Explorer which compiles successfully. It uses

In short it does

etl::array<int,10> mArray;
etl::span<int> mSpan(mArray);

Now with the compiler I have to use I get this error:

Error[Pe309]: more than one instance of constructor "etl::span<T, 65535U>::span [with T=int]" matches the argument list:
            function template "etl::span<T, 65535U>::span(etl::array<U, N> &, etl::enable_if<etl::is_same<int, etl::remove_cv<U>::type>::value, void>::type *) [with T=int]" 
            function template "etl::span<T, 65535U>::span(TContainer &, etl::enable_if<<expression>, void>::type *) [with T=int]" 
            argument types are: (Array) 

The problem seems to be that IAR's overload resolution recognizes both constructor candidates as equally good during overload resolution.

Before suggesting a patch I wonder: Why are there both definitions:

The latter does cover the first case equally well?

I think the code is currently correct as it is. But it contains (unnecessary?) overloads which the IAR chokes on.

jwellbelove commented 10 months ago

I have a fix that I will push very soon.

dhebbeker commented 10 months ago

Thank you!

jwellbelove commented 10 months ago

Actually, I may have been too hasty. I've been working on #754, not this one. What was your suggested fix?

jwellbelove commented 10 months ago

You are correct, span(TContainer& a) works fine for std & etl arrays.

dhebbeker commented 10 months ago

I would have removed span(etl::array<U, N>& a). But I see you did this already in 01d96609cf5193f9a5b8f90cd8a1a23a5ea05631 šŸ‘

I tested that commit with the IAR compiler mentioned above. The code (same as the one referenced in the description) now compiles without compiler errors šŸ„³

šŸ™ Thank you!

jwellbelove commented 9 months ago

Fixed 20.38.2