Add code modification hints to various parsing-related diagnostics.
Plus, reword a extension warnings to avoid talking about "ISO C" when
the extension might also be available in C++ or C++0x.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68257 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/DeclSpec.cpp b/lib/Parse/DeclSpec.cpp
index de9f36d..40675de 100644
--- a/lib/Parse/DeclSpec.cpp
+++ b/lib/Parse/DeclSpec.cpp
@@ -13,6 +13,7 @@
#include "clang/Parse/DeclSpec.h"
#include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/LangOptions.h"
#include "llvm/ADT/STLExtras.h"
#include <cstring>
@@ -283,9 +284,9 @@
/// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or
/// diag::NUM_DIAGNOSTICS if there is no error. After calling this method,
/// DeclSpec is guaranteed self-consistent, even if an error occurred.
-void DeclSpec::Finish(Diagnostic &D, SourceManager& SrcMgr,
- const LangOptions &Lang) {
+void DeclSpec::Finish(Diagnostic &D, Preprocessor &PP) {
// Check the type specifier components first.
+ SourceManager &SrcMgr = PP.getSourceManager();
// signed/unsigned are only valid with int/char/wchar_t.
if (TypeSpecSign != TSS_unspecified) {
@@ -330,7 +331,10 @@
// disallow their use. Need information about the backend.
if (TypeSpecComplex != TSC_unspecified) {
if (TypeSpecType == TST_unspecified) {
- Diag(D, TSCLoc, SrcMgr, diag::ext_plain_complex);
+ Diag(D, TSCLoc, SrcMgr, diag::ext_plain_complex)
+ << CodeModificationHint::CreateInsertion(
+ PP.getLocForEndOfToken(getTypeSpecComplexLoc()),
+ " double");
TypeSpecType = TST_double; // _Complex -> _Complex double.
} else if (TypeSpecType == TST_int || TypeSpecType == TST_char) {
// Note that this intentionally doesn't include _Complex _Bool.
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index e233a22..104ca03 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -496,7 +496,7 @@
DoneWithDeclSpec:
// If this is not a declaration specifier token, we're done reading decl
// specifiers. First verify that DeclSpec's are consistent.
- DS.Finish(Diags, PP.getSourceManager(), getLang());
+ DS.Finish(Diags, PP);
return;
case tok::coloncolon: // ::foo::bar
@@ -1169,7 +1169,8 @@
// Check for extraneous top-level semicolon.
if (Tok.is(tok::semi)) {
- Diag(Tok, diag::ext_extra_struct_semi);
+ Diag(Tok, diag::ext_extra_struct_semi)
+ << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation()));
ConsumeToken();
continue;
}
@@ -1372,8 +1373,11 @@
break;
SourceLocation CommaLoc = ConsumeToken();
- if (Tok.isNot(tok::identifier) && !getLang().C99)
- Diag(CommaLoc, diag::ext_c99_enumerator_list_comma);
+ if (Tok.isNot(tok::identifier) &&
+ !(getLang().C99 || getLang().CPlusPlus0x))
+ Diag(CommaLoc, diag::ext_enumerator_list_comma)
+ << getLang().CPlusPlus
+ << CodeModificationHint::CreateRemoval((SourceRange(CommaLoc)));
}
// Eat the }.
@@ -1625,7 +1629,7 @@
DoneWithTypeQuals:
// If this is not a type-qualifier token, we're done reading type
// qualifiers. First verify that DeclSpec's are consistent.
- DS.Finish(Diags, PP.getSourceManager(), getLang());
+ DS.Finish(Diags, PP);
return;
}
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index 5865771..f00eddd 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -608,7 +608,7 @@
// GNU typeof support.
case tok::kw_typeof:
ParseTypeofSpecifier(DS);
- DS.Finish(Diags, PP.getSourceManager(), getLang());
+ DS.Finish(Diags, PP);
return;
}
if (Tok.is(tok::annot_typename))
@@ -616,7 +616,7 @@
else
DS.SetRangeEnd(Tok.getLocation());
ConsumeToken();
- DS.Finish(Diags, PP.getSourceManager(), getLang());
+ DS.Finish(Diags, PP);
}
/// ParseCXXTypeSpecifierSeq - Parse a C++ type-specifier-seq (C++
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index 8903da2..5b38f60 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -372,7 +372,8 @@
DeclPtrTy SingleDecl;
switch (Tok.getKind()) {
case tok::semi:
- Diag(Tok, diag::ext_top_level_semi);
+ Diag(Tok, diag::ext_top_level_semi)
+ << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation()));
ConsumeToken();
// TODO: Invoke action for top-level semicolon.
return DeclGroupPtrTy();