Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

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

$
0
0

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


Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>