r198601 - Highlight the previous underlying enum type when diagnosing a mismatch

Alp Toker alp at nuanti.com
Mon Jan 6 03:31:18 PST 2014


Author: alp
Date: Mon Jan  6 05:31:18 2014
New Revision: 198601

URL: http://llvm.org/viewvc/llvm-project?rev=198601&view=rev
Log:
Highlight the previous underlying enum type when diagnosing a mismatch

enum-scoped.cpp:93:6: error: enumeration redeclared with different underlying type 'short' (was 'int')
  enum Redeclare6 : short;
       ^
enum-scoped.cpp:92:6: note: previous declaration is here
  enum Redeclare6 : int;
       ^            ~~~

The redeclaration source range is still missing but this is a step forward,
potentially edging towards a FixIt.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=198601&r1=198600&r2=198601&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Jan  6 05:31:18 2014
@@ -2900,6 +2900,10 @@ public:
     return IntegerType.dyn_cast<TypeSourceInfo*>();
   }
 
+  /// \brief Retrieve the source range that covers the underlying type if
+  /// specified.
+  SourceRange getIntegerTypeRange() const LLVM_READONLY;
+
   /// \brief Returns the width in bits required to store all the
   /// non-negative enumerators of this enum.
   unsigned getNumPositiveBits() const {

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=198601&r1=198600&r2=198601&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Jan  6 05:31:18 2014
@@ -3280,6 +3280,12 @@ EnumDecl *EnumDecl::CreateDeserialized(A
   return Enum;
 }
 
+SourceRange EnumDecl::getIntegerTypeRange() const {
+  if (const TypeSourceInfo *TI = getIntegerTypeSourceInfo())
+    return TI->getTypeLoc().getSourceRange();
+  return SourceRange();
+}
+
 void EnumDecl::completeDefinition(QualType NewType,
                                   QualType NewPromotionType,
                                   unsigned NumPositiveBits,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=198601&r1=198600&r2=198601&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan  6 05:31:18 2014
@@ -10257,9 +10257,11 @@ bool Sema::CheckEnumRedeclaration(Source
         !Prev->getIntegerType()->isDependentType() &&
         !Context.hasSameUnqualifiedType(EnumUnderlyingTy,
                                         Prev->getIntegerType())) {
+      // TODO: Highlight the underlying type of the redeclaration.
       Diag(EnumLoc, diag::err_enum_redeclare_type_mismatch)
         << EnumUnderlyingTy << Prev->getIntegerType();
-      Diag(Prev->getLocation(), diag::note_previous_declaration);
+      Diag(Prev->getLocation(), diag::note_previous_declaration)
+          << Prev->getIntegerTypeRange();
       return true;
     }
   } else if (IsFixed != Prev->isFixed()) {





More information about the cfe-commits mailing list