diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-12 23:53:29 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-12 23:53:29 +0000 |
commit | 7984de35644701c0d94336da7f2215d4c26d9f5b (patch) | |
tree | 6a925ab1c97321c244d1b77502996ef7607ab95e /lib/Sema/SemaFixItUtils.cpp | |
parent | 83be12c8638a5136b937e602b3a9e25f4bc8e50d (diff) |
Improve 0-argument -Wvexing-parse diagnostic by adding notes with fix-its:
- If the declarator is at the start of a line, and the previous line contained
another declarator and ended with a comma, then that comma was probably a
typo for a semicolon:
int n = 0, m = 1, l = 2, // k = 5;
myImportantFunctionCall(); // oops!
- If removing the parentheses would correctly initialize the object, then
produce a note suggesting that fix.
- Otherwise, if there is a simple initializer we can suggest which performs
value-initialization, then provide a note suggesting a correction to that
initializer.
Sema::Declarator now tracks the location of the comma prior to the declarator in
the declaration, if there is one, to facilitate providing the note. The code to
determine an appropriate initializer from the -Wuninitialized warning has been
factored out to allow use in both that and -Wvexing-parse.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaFixItUtils.cpp')
-rw-r--r-- | lib/Sema/SemaFixItUtils.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Sema/SemaFixItUtils.cpp b/lib/Sema/SemaFixItUtils.cpp index 8e8a46da73..1f17a9e83e 100644 --- a/lib/Sema/SemaFixItUtils.cpp +++ b/lib/Sema/SemaFixItUtils.cpp @@ -158,3 +158,31 @@ bool ConversionFixItGenerator::tryToFixConversion(const Expr *FullExpr, return false; } + +const char *Sema::getFixItZeroInitializerForType(QualType T) const { + // Suggest 'nil' if it's defined and appropriate. + if ((T->isObjCObjectPointerType() || T->isBlockPointerType()) && + PP.getMacroInfo(&getASTContext().Idents.get("nil"))) + return " = nil"; + if (T->isRealFloatingType()) + return " = 0.0"; + if (T->isBooleanType() && LangOpts.CPlusPlus) + return " = false"; + if (T->isPointerType() || T->isMemberPointerType()) { + if (LangOpts.CPlusPlus0x) + return " = nullptr"; + // Check if 'NULL' is defined. + else if (PP.getMacroInfo(&getASTContext().Idents.get("NULL"))) + return " = NULL"; + } + if (T->isEnumeralType()) + return 0; + if (T->isScalarType()) + return " = 0"; + const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); + if (LangOpts.CPlusPlus0x && RD && !RD->hasUserProvidedDefaultConstructor()) + return "{}"; + if (T->isAggregateType()) + return " = {}"; + return 0; +} |