From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15064 invoked from network); 23 Dec 2021 19:13:28 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 23 Dec 2021 19:13:28 -0000 Received: (qmail 20240 invoked by uid 550); 23 Dec 2021 19:13:25 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 20205 invoked from network); 23 Dec 2021 19:13:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:from:date:message-id:subject:to:cc; bh=JEHs2YG/syVotMfvNXl7nHq3MEfA3p/W/q17HBE+F5U=; b=cstJN12rzkLMLWmP3F+a3C9dwQeVHoVj3B7E5UVK7zUYp0ncSTXNNYqKtjVxY5VtLc ip2SE+m7uf7fbcVdxYpsbPuBd2lxR9DG7jRlQwsLCon0ILN/Wa3ZGZKUH+QGbuWBZC0H Q7wkYBeRNpB+Eu9m/TIidSWTKrG5CsHDxJoLB9n2ppPpJsze0AuH9F94E1KW8X3iRK5c 8BXiiBvPRk9a1WXa8HVIP1H+vE6bZSttuYbmUyEKI2UA945+K3eEJaLp90kxKSQLVmeg bYFM0kZh4Donx7X6W2+E6zyLaxN43NNqu228kuY6Wcb3LwyWrojDREjFZXqBrC6/Ypgo dwTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=JEHs2YG/syVotMfvNXl7nHq3MEfA3p/W/q17HBE+F5U=; b=YU9lNw3GASE9KDYsXU0kPwywwxE4Ek9rbnUpuADLepay/pPopW11fZrdcnnKkje0Zl tkyccoJzFeMaMvia13nGGV+yPQ9OvRiBKNb3gtzGQuR01NlobqNbxrWvxA8QFBgvII4x m90AsmTS492sUfOFrhclfKyr/mM0boRgGRdmoZVYbAZ4hAy/jAYVaUalIdophDPk8yW/ MoYmo8yz/bhUMaDL0n7vuVNWo2JjA/liS/5fFgRczGweehU3vvLlKcWp1u+FOCPw/Fln bHxPSXvQ6d4EsDr+aiUJOJvzW3PpqucQiZTpqEgV54+eXB7tkCSzzKShbPlrrWFG2vA0 QhRg== X-Gm-Message-State: AOAM532wo9cE8Q82Zgvj9EuV993TEm0wFxPIGDcpPr8Cm/RjmCihOwI4 JpiZdfAZ+HIWindFJjXouYHtNJX+suxg+NxyDghJ+3ed4Mp8xQ== X-Google-Smtp-Source: ABdhPJxULc3JEJo/ejrk4E3/0oF/Vw/WVMWtjGyj/Mq3QhWMW9bGeKbKMRwHTlA3M23MnwDeyee0qaHLxFVC3K8JQkw= X-Received: by 2002:a25:8408:: with SMTP id u8mr5066443ybk.258.1640286792974; Thu, 23 Dec 2021 11:13:12 -0800 (PST) MIME-Version: 1.0 From: Colin Cross Date: Thu, 23 Dec 2021 11:13:01 -0800 Message-ID: To: musl@lists.openwall.com Cc: Ismael Luceno Content-Type: text/plain; charset="UTF-8" Subject: [musl] Re: [PATCH] Define NULL as nullptr when used in C++ On Sun, Aug 15, 2021 at 05:51:57PM +0200, Ismael Luceno wrote: > This should be safer for casting and more compatible with existing code > bases that wrongly assume it must be defined as a pointer. This seems to meet the C++ spec for NULL [1], but I noticed some compatibility issues with code that was previously compiling with glibc. I've found multiple places that used reinterpret_cast(NULL), which now fail with: error: reinterpret_cast from 'nullptr_t' to 'int *' is not allowed According to [2] those should technically be static_cast and not reinterpret_cast. I've also seen failures with returning NULL from a function with a jlong return type: error: cannot initialize return object of type 'jlong' (aka 'long') with an rvalue of type 'nullptr_t' glibc uses __null if __GNUG__ is set, ((void*)0) for __cplusplus, or 0 for C. This also meets the C++ spec for NULL [1], but is an improvement over the previous 0L because it can be correctly interpreted as a NULL sentinel value by Clang's -Wsentinel warning. Ismael, can you give an example of the code that assumes NULL is a pointer? Does it work with __null (assuming you're using a compiler that has GNU extensions like __null)? In any case, I'll fix the technically incorrect code I have access to so that it works with nullptr. [1] https://en.cppreference.com/w/cpp/types/NULL [2] https://en.cppreference.com/w/cpp/language/reinterpret_cast