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

Duncan P. N. Exon Smith via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 26 16:12:40 PDT 2018


> On Mar 26, 2018, at 02:50, Kareem Khazem via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi all,
> 
> Clang 6.0 complains about the string "<=>" even when it's a stringified macro
> rather than a token. Is this expected behaviour?

I don't think so – please file a bug.

> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list