diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Sema/SemaFixItUtils.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Sema/SemaFixItUtils.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/contrib/llvm/tools/clang/lib/Sema/SemaFixItUtils.cpp b/contrib/llvm/tools/clang/lib/Sema/SemaFixItUtils.cpp index 8e8a46d..b78ea7d 100644 --- a/contrib/llvm/tools/clang/lib/Sema/SemaFixItUtils.cpp +++ b/contrib/llvm/tools/clang/lib/Sema/SemaFixItUtils.cpp @@ -158,3 +158,47 @@ bool ConversionFixItGenerator::tryToFixConversion(const Expr *FullExpr, return false; } + +static bool isMacroDefined(const Sema &S, StringRef Name) { + return S.PP.getMacroInfo(&S.getASTContext().Idents.get(Name)); +} + +const char *Sema::getFixItZeroInitializerForType(QualType T) const { + if (T->isScalarType()) { + // Suggest " = 0" for non-enumeration scalar types, unless we can find a + // better initializer. + if (T->isEnumeralType()) + return 0; + if ((T->isObjCObjectPointerType() || T->isBlockPointerType()) && + isMacroDefined(*this, "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"; + else if (isMacroDefined(*this, "NULL")) + return " = NULL"; + } + if (T->isCharType()) + return " = '\\0'"; + if (T->isWideCharType()) + return " = L'\\0'"; + if (T->isChar16Type()) + return " = u'\\0'"; + if (T->isChar32Type()) + return " = U'\\0'"; + return " = 0"; + } + + const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); + if (!RD || !RD->hasDefinition()) + return 0; + if (LangOpts.CPlusPlus0x && !RD->hasUserProvidedDefaultConstructor()) + return "{}"; + if (RD->isAggregate()) + return " = {}"; + return 0; +} |