[c++2a] P0515R3: lexer support for new <=> token.

llvm-svn: 319509
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 67dcff6..b069719 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -3522,6 +3522,24 @@
         Kind = tok::lessless;
       }
     } else if (Char == '=') {
+      char After = getCharAndSize(CurPtr+SizeTmp, SizeTmp2);
+      if (After == '>') {
+        if (getLangOpts().CPlusPlus2a) {
+          if (!isLexingRawMode())
+            Diag(BufferPtr, diag::warn_cxx17_compat_spaceship);
+          CurPtr = ConsumeChar(ConsumeChar(CurPtr, SizeTmp, Result),
+                               SizeTmp2, Result);
+          Kind = tok::spaceship;
+          break;
+        }
+        // Suggest adding a space between the '<=' and the '>' to avoid a
+        // change in semantics if this turns up in C++ <=17 mode.
+        if (getLangOpts().CPlusPlus && !isLexingRawMode()) {
+          Diag(BufferPtr, diag::warn_cxx2a_compat_spaceship)
+            << FixItHint::CreateInsertion(
+                   getSourceLocation(CurPtr + SizeTmp, SizeTmp2), " ");
+        }
+      }
       CurPtr = ConsumeChar(CurPtr, SizeTmp, Result);
       Kind = tok::lessequal;
     } else if (LangOpts.Digraphs && Char == ':') {     // '<:' -> '['