From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 804503858C41 for ; Wed, 7 Aug 2024 15:06:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 804503858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 804503858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723043189; cv=none; b=HVayzeQ/XLlIROXeOI7vYvEl4htzm/MlnkmLKwv2fU0CZusFyl2BfzMNjOv7oQ7PvAJ0iby84f3lN4X2N5iFuCHZ8PJlZKKhIekNMX8oQTXwK/rFFbQV7WBuxke3cC5kXrGVruykd057QfJc38UJF8tUx8wsS0SjoWVqgU/qnj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723043189; c=relaxed/simple; bh=17oL2rcK4eK1Hl5tC6p0Lw7sj1B7R8T0ks0IVTkqBu8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=JTAhWRXW4Xgk82gHXRyXvwSF5h0Oto/z7WvqgkiAdN5t/pe9YJB3eWxsn7qLNNLxrtKDnvrC8I2M+wjXt/za/fzSk2PVdU8rGoWw6XLwYH1B1Ho+osBCN13VBOfhhOxy/Tt7bV0cAM8KHF5YQkmt9wCrbJCaELuCPTbWQiXo5fw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723043187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hyGDxCa5zJVgBqAG96qvHyT7iYSTWRig2F5alIn1EIQ=; b=HOX58SLzSIg3TUCjhAZD9ZHGhsUg6g+mhXbrMmXDudsXLQenNZYBZbGf94w2GAw/ZskLXv 8HD5jTyP/8CDUuBR5ZPs9ftjZsvbdGem5deOoyAQJ4fwf3+NeTHfHsEj2sgyduBog68ToD YSKdKN2om8dg9SIZBlsvJ6y1QN46f7E= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-JXG69qXNOcWTM486nmfJ_Q-1; Wed, 07 Aug 2024 11:06:25 -0400 X-MC-Unique: JXG69qXNOcWTM486nmfJ_Q-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-428ea5b1479so13331425e9.0 for ; Wed, 07 Aug 2024 08:06:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723043184; x=1723647984; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hyGDxCa5zJVgBqAG96qvHyT7iYSTWRig2F5alIn1EIQ=; b=cFqWD1g/S4QY1XZoYFsT2vKM+ctk9BZ9nV3QgB/zzBzFB4UgHxP7L7jFPC2/Sju4/d VoVtclEC9Gu0o/irD+9cHM3q5NH72Q3X6WFnehpxb27/lH1xFcJji4bkMxrMMzkHgzaK eV30L+8dgGq7Y3+FixgEQGat4edQMfF1JNn8UFJBXk2muI58N0/AoOKzgCgAGzuVO7yB PTmeMAOpjo9AqgfEoql5bJWlkXfW01DwY6BUWl+qBxzEM02b3cHUa1IK6ws3kXYhUAJ0 sHL0CZ4ZsDWrOvjeiDeZwpzhH5/wq/sS53MpR1Y1iXZcjwMGWG6h1sme2mDCuzlQYrW8 7UBA== X-Gm-Message-State: AOJu0YywxgBJf5X/MYlEEflLKCYOIVu/MnbBRNShiANjbiO6L1RNPDkI 1nqZ2nO3ZWvsBHIA2RZFN083UgbCdd2eLbaxbgNOd4dANno1HgIjegoe6wd2q3yeNpxmZ5lXKut yWgwVwUH8D/YFhmQgM3WakQSN5TW26Olv+KPi7ous1lqkpeAQayLbV/Y= X-Received: by 2002:a05:600c:46d5:b0:428:e820:37ae with SMTP id 5b1f17b1804b1-428e8203c23mr125080345e9.1.1723043184274; Wed, 07 Aug 2024 08:06:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3JhlE4TXqeuovao0VTsHn701Y8jdjTxbrGhtM78QE9FEmGlTrOei8t+E2dRRYAbQXMVkZ6Q== X-Received: by 2002:a05:600c:46d5:b0:428:e820:37ae with SMTP id 5b1f17b1804b1-428e8203c23mr125080095e9.1.1723043183750; Wed, 07 Aug 2024 08:06:23 -0700 (PDT) Received: from digraph.polyomino.org.uk (digraph.polyomino.org.uk. [2001:8b0:bf73:93f7::51bb:e332]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429059a5b38sm34316925e9.33.2024.08.07.08.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 08:06:23 -0700 (PDT) Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.95) (envelope-from ) id 1sbiEW-00CbuM-Qm; Wed, 07 Aug 2024 15:05:48 +0000 Date: Wed, 7 Aug 2024 15:05:48 +0000 (UTC) From: Joseph Myers To: Alejandro Colomar cc: gcc-patches@gcc.gnu.org, Martin Uecker , Xavier Del Campo Romero , Gabriel Ravier , Jakub Jelinek , Kees Cook , Qing Zhao , Jens Gustedt , David Brown , Florian Weimer , Andreas Schwab Subject: Re: [PATCH v5 3/3] c: Add __lengthof__ operator In-Reply-To: <20240806231151.1046913-4-alx@kernel.org> Message-ID: References: <20240728141547.302478-1-alx@kernel.org> <20240806231151.1046913-1-alx@kernel.org> <20240806231151.1046913-4-alx@kernel.org> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, 7 Aug 2024, Alejandro Colomar wrote: > +@node Length > +@section Determining the Length of Arrays > +@cindex lengthof > +@cindex length > +@cindex array length > + > +The keyword @code{__lengthof__} determines the length of an array operand, > +that is, the number of elements in the array. > +Its syntax is just like @code{sizeof}. > +The operand must be a complete array type. I think you mean the operand must be *an expression whose type is a complete array type* or *a type name for a complete array type*. The wording you have suggests only type names, you need to be clear about both kinds of operands being possible (and include examples for them). > +@smallexample > +__lengthof__ (int [7][n++]); // constexpr > +__lengthof__ (int [n++][7]); // run-time value > +@end smallexample I don't think using "constexpr" to mean "constant expression" is a good idea, they're different things. > +void > +incomplete (int p[]) > +{ > + unsigned n; > + > + n = __lengthof__ (x); /* { dg-error "incomplete" } */ > + > + /* We want to support the following one in the future, > + but for now it should fail. */ > + n = __lengthof__ (p); /* { dg-error "invalid" } */ This seems to be the only test you have for a non-array operand. I'd expect such tests (both for type name operands and for expression operands) covering cases that we *don't* want to support in future, not just this one that we would like to be supportable in future. I don't see any tests for the constraints on external definitions from 6.9.1 that we discussed - that referenced to undefined internal linkage identifiers are OK inside __lengthof__ returning a constant (both constant-length arrays of non-VLA and constant-length arrays of VLA) but not in the cases where __lengthof__ is evaluated. -- Joseph S. Myers josmyers@redhat.com