r198666 - Bring back magic constants in the digraph diagnostic

Alp Toker alp at nuanti.com
Mon Jan 6 18:35:34 PST 2014


Author: alp
Date: Mon Jan  6 20:35:33 2014
New Revision: 198666

URL: http://llvm.org/viewvc/llvm-project?rev=198666&view=rev
Log:
Bring back magic constants in the digraph diagnostic

This backs out changes in commit r198605 and part of r198604, replacing the
original tok::kw_template with a slightly more obvious placeholder
tok::unknown.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Parse/ParseExprCXX.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=198666&r1=198665&r2=198666&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon Jan  6 20:35:33 2014
@@ -640,7 +640,9 @@ def err_ctor_init_missing_comma : Error<
 def err_friend_decl_defines_type : Error<
   "cannot define a type in a friend declaration">;
 def err_missing_whitespace_digraph : Error<
-  "found '<::' after a %0 which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?">;
+  "found '<::' after a "
+  "%select{template name|const_cast|dynamic_cast|reinterpret_cast|static_cast}0"
+  " which forms the digraph '<:' (aka '[') and a ':', did you mean '< ::'?">;
 
 def ext_deleted_function : ExtWarn<
   "deleted function definitions are a C++11 extension">, InGroup<CXX11>;

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=198666&r1=198665&r2=198666&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Mon Jan  6 20:35:33 2014
@@ -646,8 +646,6 @@ static const char *getTokenDescForDiagno
   switch (Kind) {
   case tok::identifier:
     return "identifier";
-  case tok::annot_template_id:
-    return "template name";
   default:
     return 0;
   }

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=198666&r1=198665&r2=198666&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Mon Jan  6 20:35:33 2014
@@ -24,6 +24,20 @@
 
 using namespace clang;
 
+static int SelectDigraphErrorMessage(tok::TokenKind Kind) {
+  switch (Kind) {
+    // template name
+    case tok::unknown:             return 0;
+    // casts
+    case tok::kw_const_cast:       return 1;
+    case tok::kw_dynamic_cast:     return 2;
+    case tok::kw_reinterpret_cast: return 3;
+    case tok::kw_static_cast:      return 4;
+    default:
+      llvm_unreachable("Unknown type for digraph error message.");
+  }
+}
+
 // Are the two tokens adjacent in the same source file?
 bool Parser::areTokensAdjacent(const Token &First, const Token &Second) {
   SourceManager &SM = PP.getSourceManager();
@@ -44,7 +58,8 @@ static void FixDigraph(Parser &P, Prepro
   Range.setBegin(DigraphToken.getLocation());
   Range.setEnd(ColonToken.getLocation());
   P.Diag(DigraphToken.getLocation(), diag::err_missing_whitespace_digraph)
-      << Kind << FixItHint::CreateReplacement(Range, "< ::");
+      << SelectDigraphErrorMessage(Kind)
+      << FixItHint::CreateReplacement(Range, "< ::");
 
   // Update token information to reflect their change in token type.
   ColonToken.setKind(tok::coloncolon);
@@ -80,8 +95,8 @@ void Parser::CheckForTemplateAndDigraph(
                               Template, MemberOfUnknownSpecialization))
     return;
 
-  FixDigraph(*this, PP, Next, SecondToken, tok::annot_template_id,
-             /*AtDigraph*/ false);
+  FixDigraph(*this, PP, Next, SecondToken, tok::unknown,
+             /*AtDigraph*/false);
 }
 
 /// \brief Emits an error for a left parentheses after a double colon.





More information about the cfe-commits mailing list