On Wed, 24 Aug 2022, Marek Polacek via Gcc-patches wrote:

> Ah, okay.  I had just copied what we do in C++ in null_ptr_cst_p and the
> rest of the patch worked under that assumption.  I've added some tests
> for this too.  Except I don't really understand the _Generic comment so
> I only have tests for _Generic that were in the previous version.

The point is that e.g.

_Generic(0, int : nullptr)

is treated the same as nullptr (so is a null pointer constant), just as 
(nullptr) is.

> Thanks, tests added to c2x-nullptr-1.c:test1.  I notice that 6.3.2.4 still
> says "The type nullptr_t may be converted to bool or to a pointer type";
> isn't it missing the ", void" here too?

In general none of the subclauses under 6.3.2 about individual kinds of 
types tend to discuss the possibility of conversion to void.

> +/* Simple assignment.  */
> +void
> +test4 (void)
> +{
> +  /* -- the left operand has an atomic, qualified, or unqualified version of
> +     the nullptr_t type and the type of the right is nullptr_t;  */
> +  nullptr_t n1;
> +  n1 = nullptr;
> +  const nullptr_t n2 = nullptr;
> +  _Atomic nullptr_t n3 = nullptr;
> +  volatile nullptr_t n4 = nullptr;

These qualified cases are all actually initialization, not assignment; I 
think both assignment and initialization (and argument passing and return) 
should be tested for the permitted cases for assignment.

> +/* Test nullptr_t from <stddef.h..  */

Typo, "<stddef.h." should be <stddef.h>".

> +/* If a second or third operand of type nullptr_t is used that is not a null
> +   pointer constant and the other operand is not a pointer or does not have
> +   itself nullptr_t, a constraint is violated even if that other operand is
> +   a null pointer constant such as 0.  */

The "that is not a null pointer constant" in that footnote is a bit odd, 
since it's also a constraint violation (and should be tested as such) to 
have a conditional expression between e.g. nullptr and 0.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to