[llvm-bugs] [Bug 49008] New: false positive -Wzero-as-null-pointer-constant involving spaceship operator

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 2 20:00:04 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=49008

            Bug ID: 49008
           Summary: false positive -Wzero-as-null-pointer-constant
                    involving spaceship operator
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mizvekov at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Clang produces very confusing diagnostics with -Wzero-as-null-pointer-constant,
involving spaceship comparisons.

The example below is a creduction with further manual intervention from a
program compiled for mingw32, where this warning would get triggered for
seemingly innocent comparisons.

clang++ -Wzero-as-null-pointer-constant -std=c++20 -fsyntax-only test.cc
```
namespace std {
struct strong_ordering {
  int n;
  constexpr strong_ordering(int n) : n(n) {}
  static const strong_ordering less, equal, greater;
  friend constexpr bool operator<(strong_ordering a, void*) { return a.n; }
};
constexpr strong_ordering strong_ordering::less{-1}, strong_ordering::equal{0},
strong_ordering::greater{1};
} // namespace std

struct bb { int bf; };
constexpr auto operator<=>(bb bl, bb bm) { return bl.bf <=> bm.bf; }
static_assert(bb{0} < bb{1});
```

Compiler output:

```
test.cc:13:21: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
static_assert(bb{0} < bb{1});
                    ^
                    nullptr
test.cc:12:16: note: while rewriting comparison as call to 'operator<=>'
declared here
constexpr auto operator<=>(bb bl, bb bm) { return bl.bf <=> bm.bf; }
               ^
1 warning generated.
```

Workspace for convenience: https://godbolt.org/z/5sxz4c

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210203/ecd42e4d/attachment.html>


More information about the llvm-bugs mailing list