From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by sourceware.org (Postfix) with ESMTPS id EE6CC38312A1 for ; Mon, 6 Jun 2022 18:42:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EE6CC38312A1 Received: by mail-qk1-x72d.google.com with SMTP id o68so11541101qkf.13 for ; Mon, 06 Jun 2022 11:42:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=t3ow21WyHkGUnHKf2MMOc14Jpvng7lcTN4Tn+NdU518=; b=Ly18S7+cNVF+r7TaCvNK0EIghUl/z94k3krZDtrLUUS6E/Fy+rZLoFhrAip4GtTqXv HKW/a2SnW03Ymcd578ZBzsDlm3rPJ4WYXKjDNBJiWVlXeEGYIeeuiHl4sfOaPjRPCTrc uyUNJrJokEjJsHsGo6Pc2mIHxF6nhafPcyRGT3f4ftT1WWQ3LxyfyU+Vcrw/M8qtj5fZ O6+m3TxG0qKhciLRJwsFyZ1XAcP304x16kNYJK9YfKBs1t79Ie72fJCbpQoVkaCjhWHG +lwLeLe8g6nSZ1XgrZoXezf/kZEdceynFmzocJKAFbFi6mOEXhR81U/n4gfv7YrDRCBq JMQQ== X-Gm-Message-State: AOAM533UjPrnIslzEDD2kHL0wavESbd4Iyx/Adl0AvT+cA58UK3IU7ZB mF3SYLwN/twt4ogyoEewY5YGv1hDBCWc2s5Y X-Google-Smtp-Source: ABdhPJweMtEo588R5oHLeWZY5NAz4L9Yma8AhNUkNYj4G34aEOjds2/anjt8aXKcPlwYG6W6pNXRUg== X-Received: by 2002:a05:620a:1676:b0:6a6:b1c7:185a with SMTP id d22-20020a05620a167600b006a6b1c7185amr7317230qko.33.1654540966329; Mon, 06 Jun 2022 11:42:46 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id m16-20020a05620a291000b006a6bb044740sm3583508qkp.66.2022.06.06.11.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 11:42:45 -0700 (PDT) Date: Mon, 6 Jun 2022 14:42:45 -0400 From: Ben Boeckel To: Miika Cc: "gcc@gcc.gnu.org" Subject: Re: [RFC] Support for nonzero attribute Message-ID: References: <6PeOfngSW_gLKMPtqp7UWs9ZQRv6KpLer221P_B9lNGGC7nJD0p-ta_7b0fwgSdz6cw7UzXsO0OGg0t2UUux81cVfIZkQcbjPwcRHFsNomI=@protonmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <6PeOfngSW_gLKMPtqp7UWs9ZQRv6KpLer221P_B9lNGGC7nJD0p-ta_7b0fwgSdz6cw7UzXsO0OGg0t2UUux81cVfIZkQcbjPwcRHFsNomI=@protonmail.com> User-Agent: Mutt/2.2.1 (2022-02-19) X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jun 2022 18:42:48 -0000 On Sun, Jun 05, 2022 at 20:09:04 +0000, Miika via Gcc wrote: > Based on Jakub's and Yair's comments I created a new attribute "inrange". > Inrage takes three arguments, pos min and max. > Pos being the argument position in the function, and min and max defines the > range of valid integer. Both min and max are inclusive and work with enums. > Warnings are enabled with the new flag: "-Winrange". Is this something that could be applied to variables or types (I've not much experience with GCC attribute internal mechanisms, so maybe not)? For example: ``` // This variable must be in range. int percentage __attribute__((inrange(0, 100))); // Any variable declared through this typedef must be in range. typedef int __attribute__((inrange(0, 100))) percentage_t; ``` --Ben