]> granicus.if.org Git - clang/commitdiff
Highlight the previous underlying enum type when diagnosing a mismatch
authorAlp Toker <alp@nuanti.com>
Mon, 6 Jan 2014 11:31:18 +0000 (11:31 +0000)
committerAlp Toker <alp@nuanti.com>
Mon, 6 Jan 2014 11:31:18 +0000 (11:31 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198601 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Decl.h
lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp

index da72e7e00c279096c8719442c8d061c16ef21d68..09aff1b39790eb57542dc8bb3d7610e209bc663f 100644 (file)
@@ -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 {
index 754f790d8b0cbb8ae474f62e2a43bfd7ee510993..29443960c47d8ee50efbab6f93676da8ceebc12d 100644 (file)
@@ -3280,6 +3280,12 @@ EnumDecl *EnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
   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,
index c17510ae8a78eb64d59f3bbbf91c97f20d7f5958..07a551da2f1c4221538b6c412005813b94ba73b5 100644 (file)
@@ -10257,9 +10257,11 @@ bool Sema::CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped,
         !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()) {