-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc++] Avoid -Wzero-as-null-pointer-constant in operator<=> #79465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b91b1f6
[libc++] Avoid -Wzero-as-null-pointer-constant in operator<=>
ldionne 3da7bf5
Use diagnose_if and improve tests
ldionne 96d64ae
Use __enable_if__ attribute
ldionne 3c9161f
Avoid warning on GCC
ldionne 49418ba
Remove outdated XFAIL for msvc
ldionne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...est/std/language.support/cmp/cmp.categories.pre/reject-other-than-literal-zero.verify.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
||
// <compare> | ||
|
||
// Ensure we reject all cases where an argument other than a literal 0 is used | ||
// for a comparison against a comparison category type. | ||
|
||
// Also ensure that we don't warn about providing a null pointer constant when | ||
// comparing an ordering type against literal 0, since one of the common | ||
// implementation strategies is to use a pointer as the "unspecified type". | ||
// ADDITIONAL_COMPILE_FLAGS: -Wzero-as-null-pointer-constant | ||
|
||
#include <compare> | ||
|
||
#include "test_macros.h" | ||
|
||
#define TEST_FAIL(v, op) \ | ||
do { \ | ||
/* invalid types */ \ | ||
void(v op 0L); \ | ||
void(0L op v); \ | ||
void(v op 0.0); \ | ||
void(0.0 op v); \ | ||
void(v op nullptr); \ | ||
void(nullptr op v); \ | ||
/* invalid value */ \ | ||
void(v op 1); \ | ||
void(1 op v); \ | ||
/* value not known at compile-time */ \ | ||
int i = 0; \ | ||
void(v op i); \ | ||
void(i op v); \ | ||
} while (false) | ||
|
||
#define TEST_PASS(v, op) \ | ||
do { \ | ||
void(v op 0); \ | ||
void(0 op v); \ | ||
LIBCPP_ONLY(void(v op(1 - 1))); \ | ||
LIBCPP_ONLY(void((1 - 1) op v)); \ | ||
} while (false) | ||
|
||
template <typename T> | ||
void test_category(T v) { | ||
TEST_FAIL(v, ==); // expected-error 30 {{invalid operands to binary expression}} | ||
TEST_FAIL(v, !=); // expected-error 30 {{invalid operands to binary expression}} | ||
TEST_FAIL(v, <); // expected-error 30 {{invalid operands to binary expression}} | ||
TEST_FAIL(v, <=); // expected-error 30 {{invalid operands to binary expression}} | ||
TEST_FAIL(v, >); // expected-error 30 {{invalid operands to binary expression}} | ||
TEST_FAIL(v, >=); // expected-error 30 {{invalid operands to binary expression}} | ||
TEST_FAIL(v, <=>); // expected-error 30 {{invalid operands to binary expression}} | ||
|
||
TEST_PASS(v, ==); | ||
TEST_PASS(v, !=); | ||
TEST_PASS(v, <); | ||
TEST_PASS(v, >); | ||
TEST_PASS(v, <=); | ||
TEST_PASS(v, >=); | ||
TEST_PASS(v, <=>); | ||
} | ||
|
||
void f() { | ||
test_category(std::strong_ordering::equivalent); | ||
test_category(std::weak_ordering::equivalent); | ||
test_category(std::partial_ordering::equivalent); | ||
} |
57 changes: 0 additions & 57 deletions
57
libcxx/test/std/language.support/cmp/cmp.categories.pre/zero_type.verify.cpp
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to have regressed our ability to detect comparisons against a
const int
:My suggestion from #43670 avoided this by providing a deleted constructor overload that takes an int lvalue; could we do something similar here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#127311