[all-commits] [llvm/llvm-project] aa0884: [libc++] Avoid -Wzero-as-null-pointer-constant in ...
Louis Dionne via All-commits
all-commits at lists.llvm.org
Wed Aug 21 06:06:18 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: aa088438784dd76a859eee229ddaec17e0cb0651
https://github.com/llvm/llvm-project/commit/aa088438784dd76a859eee229ddaec17e0cb0651
Author: Louis Dionne <ldionne.2 at gmail.com>
Date: 2024-08-21 (Wed, 21 Aug 2024)
Changed paths:
M libcxx/include/__compare/ordering.h
A libcxx/test/std/language.support/cmp/cmp.categories.pre/reject-other-than-literal-zero.verify.cpp
R libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
Log Message:
-----------
[libc++] Avoid -Wzero-as-null-pointer-constant in operator<=> (#79465)
Issue #43670 describes a situation where the following comparison will
issue a warning when -Wzero-as-null-pointer-constant is enabled:
#include <compare>
auto b = (1 <=> 2) < 0;
This code uses operator<(strong_ordering, Unspecified), which is
specified by the Standard to only work with a literal 0. In the library,
this is achieved by constructing Unspecified from a pointer, which works
but has the downside of triggering the warning.
This patch uses an alternative implementation where we require that the
operator is used exactly with an int of value 0 (known at compile-time),
however that value can technically be an expression like `1 - 1`, which
makes us a bit less strict than what's specified in the Standard.
Fixes #43670
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list