This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: implement C11 _Generic


On Mon, 30 Jul 2012, Tom Tromey wrote:

> 6.3 is about conversions, and the first paragraph starts "several
> operators convert ...".  Based on this, and other such phrases in the
> text, I think the entire section applies to operators.

6.3.2.1 paragraphs 2 and 3 are phrased in terms of operators *preventing* 
conversion and certain conversions happening unless there is an operator 
to prevent them.

It seems entirely clear that you can use a function designator inside a 
braced initializer for an array of function pointers, for example, 
although an element of such an initializer is not an operand of an 
operator.

(I cannot find anything in a quick look through the ISO/IEC Directives 
Part 2 to indicate whether subclause titles such as "Other operands" are 
meant to be normative or informative.)

> However, _Generic is not called an operator in the text.  It is a
> primary expression.

A generic-selection is a primary expression.  _Generic is a keyword that 
is part of the syntax for a generic-selection.  C99 and C11 do not have a 
complete syntactic definition for "operator" anywhere (C90 did have such a 
syntax production).

> The cbrt example can be salvaged by adding a few extra generic
> associations.  This can even be easily done via a macro.
> 
> #define CLAUSE(TYPE, EXPR) \
>    const TYPE: EXPR,
>    TYPE: EXPR
> 
> #define cbrt(X) _Generic ((X), CLAUSE (double, ...), ...)

That doesn't handle volatile, or _Atomic.  If dealing with pointers you 
have restrict as well.  And in the presence of TR 18037 you have address 
space qualifiers, meaning such a macro cannot be written in a way agnostic 
to the set of address spaces on the system where the code is used.  
(Using +(X) or (X)+0 may work in some cases - if the promotions those 
cause aren't problems and it isn't a case where those operations are 
invalid.)

And to keep qualifiers here you'd need various other parts of the standard 
to be much clearer about whether qualifiers are present in the types of 
rvalues - an issue that previously hasn't been relevant.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]