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 ESMTPS id B19F93858D28 for ; Tue, 24 Jan 2023 12:17:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B19F93858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674562644; 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=V97W3NHS3OoJB6I/rDPAbn47NMsqJJLLqNyxEi9TgEU=; b=fBiSe1uVSY5jxePhcrDwjK5Q1MC+FGC3sGwvy+4uvLzJLx3J8pniYW5z1L4tTM0C47Zlx8 8mxny4nRREyFtn0reQAM1V0JZ02C72wedl2eSzCictbPpmSHP/iWOEyOllwaZp/BR+j4pV 3VcCgKYCsHe5fpfi1j1kK1oD5tsoRhc= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-549-gvsS0X1LOaCM_heQ1pLbqA-1; Tue, 24 Jan 2023 07:17:20 -0500 X-MC-Unique: gvsS0X1LOaCM_heQ1pLbqA-1 Received: by mail-lf1-f72.google.com with SMTP id n6-20020a0565120ac600b004d5a68b0f94so5184415lfu.14 for ; Tue, 24 Jan 2023 04:17:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=V97W3NHS3OoJB6I/rDPAbn47NMsqJJLLqNyxEi9TgEU=; b=sfoiQZjw++XYrc78dgnyTp2woJUIxBfUd5wjHziel+DMVQXBRoEUG1XS93b3GoOJzg sglz0R73Pm2U+w7w852MUoJnU258EJ0K8zG8Jiw3oU9CReFwZdcH1zokpTLNv2ygcpor hQlDmf0X3M/P+1ttuMhOiA8WgW+AJpsBgkiXNg9dVguic2imxrwBuGcT1bjolH9CHlTN ULNaXa2rqxUrT6oS7i7NTsV/0nlJQ4GwycFd28TG07EpMmY1sIdUOw0EuX8OVW5RuLnt WQxcZHLb2ef1QA3Beam2doX35wiYt/1hLpDXCgbZ7Iq4W5cCHIXKpUFB/RG535AYw4uW L96w== X-Gm-Message-State: AFqh2koBSgp0GO27ttVxxNE5W9UXfenAAzIcq83UUneylg6tV6fVqarp cO4q7hgu8fwHf7gBtweDxCqWh2NMQwWsN88csbATogq4FeJqVTkpSYnamRbFN2T5K9y5HRJSPG0 WAWflOQoEztXu2WvxkQxRu5cEdyV4uvgJn+VR X-Received: by 2002:a05:6512:208a:b0:4d5:ada2:b557 with SMTP id t10-20020a056512208a00b004d5ada2b557mr657050lfr.429.1674562639337; Tue, 24 Jan 2023 04:17:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXu8NM1pihDU2QZi7807WSLZrlx1bgF0WTwTt/neVnTPBKrx3uFxqDBRNbYy1Ji2AAzyTIrq3ngZz18DYFvECDw= X-Received: by 2002:a05:6512:208a:b0:4d5:ada2:b557 with SMTP id t10-20020a056512208a00b004d5ada2b557mr657047lfr.429.1674562639149; Tue, 24 Jan 2023 04:17:19 -0800 (PST) MIME-Version: 1.0 References: <871qnlfhtv.fsf@oldenburg.str.redhat.com> <20230124111019.GC3298@brightrain.aerifal.cx> <878rhsgoxn.fsf@oldenburg.str.redhat.com> <20230124112307.GE3298@brightrain.aerifal.cx> <87zga8f83f.fsf@oldenburg.str.redhat.com> In-Reply-To: <87zga8f83f.fsf@oldenburg.str.redhat.com> From: Jonathan Wakely Date: Tue, 24 Jan 2023 12:17:08 +0000 Message-ID: Subject: Re: [patch] Use __builtin_FILE and __builtin_LINE in assert implementation in C++ To: Florian Weimer Cc: Rich Felker , Paul Pluzhnikov via Libc-alpha , Paul Pluzhnikov X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.2 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_H2,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 Tue, 24 Jan 2023 at 12:08, Florian Weimer wrote: > > * Jonathan Wakely: > > >>>>> I think __builtin_FILE and __builtin_LINE are farily recent GCC/Clang > > > > Added to GCC 4.8.0 in 2012. I don't know about Clang. > > Oh, I didn't realize it's been this long. > > >> > __FILE__ expansion needs to be delayed, otherwise it refers to assert.h. > >> > > >> > I think the builtins also have the advantage that they avoid ODR > >> > violations because the definition is the same no matter what the file is > >> > called. > > > > It's not that simple though, the definition consists of the same > > sequence of tokens, but can still result in incompatible definitions: > > > > char* f() > > { > > static char array[__builtin_LINE()]; > > return array; > > } > > > > c.f. https://cplusplus.github.io/CWG/issues/2678.html > > Ugh, I was worried about something like that. And the location > functions need to be constexpr. Yes. But that's not a problem for assert because it can't be used to define objects or constants that would vary between TUs. > There's also the issue that is defined in terms of ISO C, > and ISO C specifies that __FILE__ and __LINE__ must be used. Is that > another defect? But maybe the difference is not observable because > __FILE__ cannot be redefined? I don't think it's observable. C requires the text printed by a failed assert to include "the values of the preprocessing macros __FILE__ and __LINE__ " but it doesn't require the actual tokens to appear in the definition. The built-ins do return "the values" of those macros, so that seems OK to me.