0

The following code compiles successfully with g++ 8.3 and clang 8.0.0 (compilation flags are -std=c++17 -Wall -Wextra -Werror -pedantic-errors)

struct Foo
{
};

struct Bar
{
  Bar() = default;

  Bar(Foo&&)
  {
  }
};

Bar baz()
{
  Foo foo;
  return foo;
}

int main()
{
}

Is it a bug in this compilers or a requirement of the C++ standard?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Constructor
  • 7,273
  • 2
  • 24
  • 66
  • Tell me if there's a problem with the dupe. – Guillaume Racicot Apr 30 '19 at 14:23
  • 1
    @Mark I don't know why you made this edit, I very deliberately removed the excessive amounts of vertical space because it adds nothing to the question but takes _MUCH LONGER_ to grok it. I understand that people have different preferences in whitespace formatting, but the 10 lines of code I removed add no value - it is making the code example more minimal. – Barry Apr 30 '19 at 16:01
  • @Barry "...the 10 lines of code I removed add no value..." → They add `Bar::Bar(Foo&&)` body at least. – Constructor Apr 30 '19 at 16:09
  • 1
    @Constructor ... which isn't relevant to the question. The body of that constructor doesn't affect how overload resolution behaves (and it was empty anyway... ) – Barry Apr 30 '19 at 16:10
  • @Barry It is relevant because without it the code doesn't compile. – Constructor Apr 30 '19 at 16:49
  • @Barry Edits just to change a reasonable coding style to your favorite style is something that should not be done, especially not if you actually remove code. Furthermore your edit was done after the question was closed, which pollutes the reopen queue. Please refrain from purely cosmetic edits or edits that remove code from a question. – Mark Rotteveel Apr 30 '19 at 17:07
  • 1
    @Mark I was trying to improve the question. I have no idea what you're trying to accomplish. But whatever man, you do you. – Barry Apr 30 '19 at 18:24
  • 1
    @Constructor It absolutely compiles. What it doesn't do is link, but again that's immaterial to the question of how overload resolution works in this situation. – Barry Apr 30 '19 at 18:27

0 Answers0