[cfe-dev] Spurious <=> operator warning in Clang 6.0/C++2a?

Kareem Khazem via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 26 02:50:14 PDT 2018


Hi all,

Clang 6.0 complains about the string "<=>" even when it's a stringified macro
rather than a token. Is this expected behaviour?

A minimal working example is this:

  #include <cstring>
  #include <cassert>

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

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

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

I get the following warning:

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 <=>
                 ^

I get this on Arch Linux's release package of Clang (tags/RELEASE_600/final), as
well as development tip-of-tree (LLVM 2c3af0c1 and clang 60cec38f), on Linux.

When preprocessing with `clang++ -E`, the preprocessor emits the same warning
but correctly compiles the two declarations to this:

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

The assertion succeeds (as expected) both when compiling directly, and when
doing the preprocessor step separately (i.e. clang++ -E foo.cpp > foo.i &&
clang++ foo.i && ./a.out). So clang is compiling this code correctly, but I
believe the warning is spurious because the "<=>" is not a token but a string.

Please advise if this is expected, or what might be done about it if not. Please
keep Michael and I copied into this thread. Thank you!

-- 
Kareem
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180326/2d2c4438/attachment.sig>


More information about the cfe-dev mailing list