[llvm-bugs] [Bug 36925] New: define of <=> spaceship causes spurious warning with Wc++2a-compat

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Mar 27 17:13:00 PDT 2018


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

            Bug ID: 36925
           Summary: define of <=> spaceship causes spurious warning with
                    Wc++2a-compat
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: karkhaz at karkhaz.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Clang emits this warning when compiling C++ code that contains a define for the
spaceship operator:

    foo.cpp:4:12: warning: '<=>' is a single token in C++2a; add a space to 
    avoid a change in behavior [-Wc++2a-compat]
    #define op <=>
              ^

Reproduce by compiling this code:

    #include <cstring>
    #include <cassert>

    #define op <=>
    #define xstr(s) str(s)
    #define str(s) #s

    const char *s1 = xstr(op);
    const char *s2 = "<=>";

    int main(int argc, char *argv[])
    {
      assert(strcmp(s1, s2) == 0);
      return 0;
    }

I do not expect this code to emit that warning, because the #define should be
preprocessed away. When the spaceship is used in the code (in the assignment to
s1), it has been stringified, so clang should not treat it as an operator.

Although a warning is emitted, the code compiles correctly (i.e. the string s1
is set to "<=>" and thus the assertion succeeds). So although clang is warning
about <=> being a token, it still knows to preprocess it to a string.

When only preprocessing the file using `clang -E`, the warning is still emitted
(I do not expect this behaviour), and the two declarations are compiled to the
following (as expected):

      const char *s1 = "<=>";
      const char *s2 = "<=>";

I have reproduced this behaviour with both the 6.0 release of Clang, and ToT as
of 2018-03-28 (LLVM 2c3af0c1 and clang 60cec38f) on Linux.

I found it difficult to bisect because Clang and LLVM are in different
repositories, even using a script similar to this one [0]. I would be happy to
bisect if somebody could point me to a maintained combined LLVM+clang
repository (using submodules or whatever) or let me know what your approach to
bisecting is.

The commit that introduced the warning and preprocessor code is is daf599b1b13,
so I'm copying in Richard Smith.

Thank you!

[0] https://lists.llvm.org/pipermail/llvm-dev/2014-July/074489.html

-- 
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/20180328/59161e2c/attachment.html>


More information about the llvm-bugs mailing list