Issue 144207
Summary The impossible type restrict void can be created using a conditional operator
Labels new issue
Assignees
Reporter Halalaluyafail3
    Consider the following program:
```cpp
int main(void){
	void*p=0;
	int*restrict*q=0;
	typedef typeof(1?p:q)T;
}
```
This code is accepted by Clang and MSVC, but not GCC. This code satisfies the conditional _expression_'s constraints:
> The first operand shall have scalar type.
> 
> One of the following shall hold for the second and third operands:109)
— both operands have arithmetic type;
— both operands have compatible structure or union type;
— both operands have void type;
— both operands are pointers to qualified or unqualified versions of compatible types;
— both operands have nullptr_t type;
— one operand is a pointer and the other is a null pointer constant or has type nullptr_t; or
— one operand is a pointer to an object type and the other is a pointer to a qualified or unqualified
version of void.
> 
> If either of the second or third operands has decimal floating type, the other operand shall not have
standard floating type, complex type, or imaginary type.

Section 6.5.16 "Conditional operator" Paragraphs 2, 3, and 4 ISO/IEC 9899:2024

However, the type of the conditional _expression_ is determined as such since both operands are pointers:
> If both the second and third operands are pointers, the result type is a pointer to a type qualified
with all the type qualifiers of the types referenced by both operands; if one is a null pointer constant
(other than a pointer) or has type nullptr_t and the other is a pointer, the result type is the pointer
type; if both the second and third operands have nullptr_t type, the result also has that type.
Furthermore, if both operands are pointers to compatible types or to differently qualified versions of
compatible types, the result type is a pointer to an appropriately qualified version of the composite
type; if one operand is a null pointer constant, the result has the type of the other operand; otherwise,
one operand is a pointer to void or a qualified version of void, in which case the result type is a
pointer to an appropriately qualified version of void.

Section 6.5.16 "Conditional operator" Paragraph 7 ISO/IEC 9899:2024

The type is a "pointer to an appropriately qualified version of void", and the appropriate qualifiers are specified as all of the qualifiers of the types pointed to by both operands. That is, this paragraph says the result should be a pointer to restrict qualified void. Such a type violates this constraint:
> Types other than pointer types whose referenced type is an object type and (possibly multidimensional) array types with such pointer types as element type shall not be restrict-qualified.

Section 6.7.4.1 Paragraph 2 ISO/IEC 9899:2024

So, this code should be diagnosed for violating a constraint.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to