[PATCH] D21075: Correct invalid end location in diagnostics for some identifiers.

Erik Verbruggen via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 7 07:38:01 PDT 2016


erikjv created this revision.
erikjv added reviewers: bkramer, klimek.
erikjv added a subscriber: cfe-commits.

Declaration names in DeclSpec had only their start set to a valid
location, so when the type specifier was missing, only the carret would
be shown at the first character of the name of a member declaration. Now
the whole identifier is underlined, which is useful for IDEs using
libclang.

Also, when the lookup for an identifier-expression failed, the end
location for that identifier was invalid.

Fixes PR25374.


http://reviews.llvm.org/D21075

Files:
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp

Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1335,8 +1335,11 @@
       // specifiers in each declaration, and in the specifier-qualifier list in
       // each struct declaration and type name."
       if (S.getLangOpts().CPlusPlus) {
+        auto R = DS.getSourceRange();
+        if (R.getEnd().isInvalid())
+          R.setEnd(R.getBegin());
         S.Diag(DeclLoc, diag::err_missing_type_specifier)
-          << DS.getSourceRange();
+          << R;
 
         // When this occurs in C++ code, often something is very broken with the
         // value being declared, poison it as invalid so we don't get chains of
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -2057,7 +2057,9 @@
   }
 
   // Give up, we can't recover.
-  Diag(R.getNameLoc(), diagnostic) << Name;
+  auto Builder = Diag(R.getNameLoc(), diagnostic) << Name;
+  if (Name.isIdentifier())
+    Builder << SourceRange(R.getNameLoc());
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21075.59886.patch
Type: text/x-patch
Size: 1140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160607/f7600bc4/attachment.bin>


More information about the cfe-commits mailing list