In the following example function f()
returning incomplete type A
is marked as deleted:
struct A;
A f() = delete;
It is accepted by GCC, but not in Clang, which complains:
error: incomplete result type 'A' in function definition
Demo: https://gcc.godbolt.org/z/937PEz1h3
Which compiler is right here according to the standard?
Clang is wrong.
[dcl.fct.def.general]
2 The type of a parameter or the return type for a function definition shall not be a (possibly cv-qualified) class type that is incomplete or abstract within the function body unless the function is deleted ([dcl.fct.def.delete]).
That's pretty clear I think. A deleted definition allows for an incomplete class type. It's not like the function can actually be called in a well-formed program, or the body is actually using the incomplete type in some way. The function is a placeholder to signify an invalid result to overload resolution.
Granted, the parameter types are more interesting in the case of actual overload resolution (and the return type can be anything), but there is no reason to restrict the return type into being complete here either.