Add -Wc++11-compat warning for string and character literals followed by
identifiers, in cases where those identifiers would be treated as
user-defined literal suffixes in C++11.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152198 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index a7fba80..0d388c6 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -1574,14 +1574,21 @@
 }
 
 /// LexUDSuffix - Lex the ud-suffix production for user-defined literal suffixes
-/// in C++11.
+/// in C++11, or warn on a ud-suffix in C++98.
 const char *Lexer::LexUDSuffix(Token &Result, const char *CurPtr) {
-  assert(getFeatures().CPlusPlus0x && "ud-suffix only exists in C++11");
+  assert(getFeatures().CPlusPlus);
 
   // Maximally munch an identifier. FIXME: UCNs.
   unsigned Size;
   char C = getCharAndSize(CurPtr, Size);
   if (isIdentifierHead(C)) {
+    if (!getFeatures().CPlusPlus0x) {
+      if (!isLexingRawMode())
+        Diag(CurPtr, diag::warn_cxx11_compat_user_defined_literal)
+          << FixItHint::CreateInsertion(getSourceLocation(CurPtr), " ");
+      return CurPtr;
+    }
+
     Result.setFlag(Token::HasUDSuffix);
     do {
       CurPtr = ConsumeChar(CurPtr, Size, Result);
@@ -1631,7 +1638,7 @@
   }
 
   // If we are in C++11, lex the optional ud-suffix.
-  if (getFeatures().CPlusPlus0x)
+  if (getFeatures().CPlusPlus)
     CurPtr = LexUDSuffix(Result, CurPtr);
 
   // If a nul character existed in the string, warn about it.
@@ -1714,7 +1721,7 @@
   }
 
   // If we are in C++11, lex the optional ud-suffix.
-  if (getFeatures().CPlusPlus0x)
+  if (getFeatures().CPlusPlus)
     CurPtr = LexUDSuffix(Result, CurPtr);
 
   // Update the location of token as well as BufferPtr.
@@ -1801,7 +1808,7 @@
   }
 
   // If we are in C++11, lex the optional ud-suffix.
-  if (getFeatures().CPlusPlus0x)
+  if (getFeatures().CPlusPlus)
     CurPtr = LexUDSuffix(Result, CurPtr);
 
   // If a nul character existed in the character, warn about it.