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.133.124]) by sourceware.org (Postfix) with ESMTPS id D03D83858413 for ; Tue, 24 Jan 2023 12:08:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D03D83858413 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=1674562123; 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=BWhAMIXFm7plasLPXEvpowQAhJJgPIaqDsqV0iqpDuI=; b=EjGqGLH/xdyJWzSGd5k5AnkQTAHMIqgp3JyCjULIrZrQCH5py65YUNny3lE0EIncZReCp9 mIqxdFfvVEhRwJGzHwRVBjHFzfdY42DjAJSJU4xe61ELuwZRErn/IVzXWOHI+NH4y5lmiH dFozqpz+ouBzf8VYBTrkYemOe3LohxE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-532-WK93AwqCOP6ZnNuRfY0MMA-1; Tue, 24 Jan 2023 07:08:40 -0500 X-MC-Unique: WK93AwqCOP6ZnNuRfY0MMA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF2E7884342; Tue, 24 Jan 2023 12:08:39 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.194.74]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AEFC753A0; Tue, 24 Jan 2023 12:08:38 +0000 (UTC) From: Florian Weimer To: Jonathan Wakely Cc: Rich Felker , Paul Pluzhnikov via Libc-alpha , Paul Pluzhnikov Subject: Re: [patch] Use __builtin_FILE and __builtin_LINE in assert implementation in C++ References: <871qnlfhtv.fsf@oldenburg.str.redhat.com> <20230124111019.GC3298@brightrain.aerifal.cx> <878rhsgoxn.fsf@oldenburg.str.redhat.com> <20230124112307.GE3298@brightrain.aerifal.cx> Date: Tue, 24 Jan 2023 13:08:36 +0100 In-Reply-To: (Jonathan Wakely's message of "Tue, 24 Jan 2023 11:53:55 +0000") Message-ID: <87zga8f83f.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-4.6 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: * 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. 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? Thanks, Florian