Spurious <=> operator warning in Clang 6.0/C++2a?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Spurious <=> operator warning in Clang 6.0/C++2a?

Louis Dionne via cfe-dev
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

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

signature.asc (673 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Spurious <=> operator warning in Clang 6.0/C++2a?

Louis Dionne via cfe-dev
> On Mar 26, 2018, at 02:50, Kareem Khazem via cfe-dev <[hidden email]> 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
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Spurious <=> operator warning in Clang 6.0/C++2a?

Louis Dionne via cfe-dev
On 2018-03-26T16:12:40, Duncan P. N. Exon Smith wrote:
> > On Mar 26, 2018, at 02:50, Kareem Khazem via cfe-dev <[hidden email]> 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.

Thanks Duncan---filed as bug #36925.

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

--
Kareem

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

signature.asc (673 bytes) Download Attachment