Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

[Bug report] Return type deduction for in-class friend functions

Praetorius__Simon
330 Views

In the following example, the return type of a friend function cannot be deduced:

struct B {};

template <class T>
struct A 
{
  friend auto bar(A const&)
  {
    return B{};
  }
};

int main()
{
  using L = decltype(bar(A<int>{}));
}

When defining bar outside of A it can be deduced, but requires to specify the template parameters for A again. Putting B instead of auto in the return type, the code also compiles fine.

This is related to an old stackoverflow question: https://stackoverflow.com/questions/18931993/return-type-deduction-for-in-class-friend-functions
In the answers it is referred to the standard document N3638. Both, GCC and Clang compile the code without complains. Intel icc 18 results inthe error "cannot deduce return type of function bar"

See also, the compiler explorer output using intel c++ 18: https://godbolt.org/g/69KQTt

0 Kudos
1 Reply
Viet_H_Intel
Moderator
330 Views

Hi Praetorius,

This seems to be a known issue and has been addressed. You will not encounter this issue in the next 18.0 update.

Regards,

Viet 

0 Kudos
Reply