by David Svoboda
C23, s7.18.1p5 says:
If a macro definition is suppressed to access an actual function,
or a program defines an external identifier with the name of a
generic function, the behavior is unspecified.
We believe this is an error, and the behavior should be undefined, not unspecified. There are several bits of evidence for this:
First, Annex J.2 cites it as Undefined Behavior 145:
145\. The macro definition of a generic function is suppressed to access an actual function (7.17.1, 7.18).
Next, sub-clause 7.17.1, paragraph 7 says:
It is unspecified whether any generic function declared in <stdatomic.h>
is a macro or an identifier declared with external linkage.
If a macro definition is suppressed to access an actual function,
or a program defines an external identifier with the name of a generic function,
the behavior is undefined.
This stands out is that for every other case of macro suppression, the standard says “undefined” rather than “unspecified”. Examples are 7.2 (assert), 7.5 (errno), 7.121 math_errhandling, among others.
In contrast, s7.31.4.5.1p2 says (regarding wide-string search functions):
If a macro definition of any of these generic functions is
suppressed to access an actual function, the external declaration
with this concrete type is visible.413
413) This is an obsolescent feature.
Finally, the definition of “unspecified behavior” implies that the document must provide two or more possibilities and imposes no other requirements, while the definition of ‘undefined behavior’ omits the “two or more possibilities”. Likewise, s7.18.1p5 omits the “two or more possibilities”, which suggests undefined behavior.
C23, s7.18.1p5 says:
If a macro definition is suppressed to access an actual function,
or a program defines an external identifier with the name of a
generic function, the behavior is unspecified.
Change this to:
If a macro definition is suppressed to access an actual function,
or a program defines an external identifier with the name of a
generic function, the behavior is undefined.
I would like to thank Joseph Sible, who initially raised this issue. Rajan Bhakta and the Undefined Behavior Study Group also reviewed the paper and provided useful comments.