[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 20 17:21:19 PDT 2024


ahatanak wrote:

I think this change can confuse users in some cases.

```
class Error {
public:
  Error() = default;
  Error(Error &&);
  Error &operator=(Error &&);
  explicit operator bool() const;
};

Error getError();

Error foo() {
  if (Error e = getError(1)) {
    return e;
  }
  return Error();
}
```

When the code above is compiled, clang complains that the implicitly-deleted copy constructor of 'Error' is called. This makes users wonder why `return e` isn't eligible for copy elision.

I wonder whether it would be better to check that `VD`'s type is incomplete rather than calling `containsErrors`.

https://github.com/llvm/llvm-project/pull/79788


More information about the cfe-commits mailing list