Hi Joseph! On Tue, Aug 06, 2024 at 05:38:50PM GMT, Joseph Myers wrote: > On Tue, 6 Aug 2024, Alejandro Colomar wrote: > > > - The tests seem to work as expected if I compile them manually, and > > run (the one that should be run) as a normal program. The one that > > should not be run also gives the expected diagnostics. > > Can anyone give advice of why it's not running well under the test > > suite? > > You almost certainly want to specify dg-options in the tests rather than > using the default "-ansi -pedantic" for gcc.dg.
That was the solution; yup. :) > Next question for the specification, implementation and tests: how does > this feature interact with the rules on external definitions (the contexts > in which it's OK to refer to an identifier with internal or external > linkage that's never defined - for example, a function, static or extern, > with a declaration but no definition; see 6.9.1)? Functions are not array types, so they don't apply. It's a constraint violation --mandatory error-- to call __lengthof__(func). VLAs cannot have static storage duration or file scope. Any array that has static storage duration or extern linkage must be a normal array. Since normal arrays operands are not evaluated, __lengthof__ returns a constant expression, and there's no issue at all. I can't think of any case where we'd have problems; do you have any other example? > My expectation would be > that the rules are analogous to those for sizeof and typeof: in the cases > where this operator does not evaluate its operand, it's also OK to > reference an identifier that's declared but not defined, but in the cases > where the operand is evaluated, that's not OK. (See gcc.dg/c99-static-1.c > for example tests of these rules for sizeof.) - Non-arrays are not valid operands to __lengthof__, of course. - We only evaluate the operand if the top-level array is a VLA, which cannot happen at file scope, nor with objects with static storage duration, nor with objects with external linkage. - So, everything is a constexpr in these cases, which is fine. Thanks for being so pedantic! It helps a lot. :-) Have a lovely night! Alex -- <https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature