You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]).
Consider these examples
Example 1:
structC;
template<classT>
structD{
autoshow(){
returnreinterpret_cast<C&&>((int&&)0); // ignore the UB here
}
};
Example 2:
structC;
structD{
template<classT>
T show(){
returnreinterpret_cast<C&&>((int&&)0); // ignore the UB here
}
};
Example 3:
structC;
structD{
template<classT>
C show(){
return T{};
}
};
Example 4:
structC;
structD{
autoshow(){
returnreinterpret_cast<C&&>((int&&)0); // ignore the UB here
}
};
The first two examples are accepted by both GCC and Clang. Conversely, the last two are rejected by both of them. It seems [dcl.fct.def.general] p2 didn't cover the templated entity case where the return type or parameter types are placeholder types or dependent types. The modification is that:
If the function definition is not for a templated function:
the type of a parameter or the return type(possibly deduced from placeholder type deduction) shall not be a (possibly cv-qualified) class type that is incomplete or abstract within the function body unless the function is deleted.
Otherwise
if the type is a placeholder type or a dependent type:
the type shall not be a (possibly cv-qualified) class type that is incomplete or abstract at the point of instantiation unless the function is deleted.
Otherwise
the type shall not be a (possibly cv-qualified) class type that is incomplete or abstract within the function body at the definition context unless the function is deleted.
The text was updated successfully, but these errors were encountered:
In general, the original rule is needed because we need complete types when generating machine code for a function definition. So, it only applies to fully-instantiated function definitions. I agree the current phrasing is a bit ambiguous.
[dcl.fct.def.general] p2
Consider these examples
Example 1:
Example 2:
Example 3:
Example 4:
The first two examples are accepted by both GCC and Clang. Conversely, the last two are rejected by both of them. It seems [dcl.fct.def.general] p2 didn't cover the templated entity case where the return type or parameter types are placeholder types or dependent types. The modification is that:
The text was updated successfully, but these errors were encountered: