Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -2282,6 +2282,15 @@ } else { Type.getAsStringInternal(Result, Policy); } + if (Param->hasDefaultArg()) { + APValue *defaultValue = Param->evaluateValue(); + if (defaultValue) { + std::string defaultValueStr = defaultValue->getAsString( + Param->getASTContext(), Param->getType()); + if (!defaultValueStr.empty()) + Result += " = " + defaultValueStr; + } + } return Result; } @@ -2398,6 +2407,13 @@ return Result; } +static std::string GetDefaultValueString(const ParmVarDecl *Param, + const SourceManager &SM, + const LangOptions &LangOpts) { + const SourceRange SrcRange = Param->getDefaultArg()->getSourceRange(); + return Lexer::getSourceText(CharSourceRange::getTokenRange(SrcRange), SM, LangOpts); +} + /// \brief Add function parameter chunks to the given code completion string. static void AddFunctionParameterChunks(Preprocessor &PP, const PrintingPolicy &Policy, @@ -2426,11 +2442,17 @@ FirstParameter = false; else Result.AddChunk(CodeCompletionString::CK_Comma); - + InOptional = false; // Format the placeholder string. std::string PlaceholderStr = FormatFunctionParameter(Policy, Param); + if (Param->hasDefaultArg() && PlaceholderStr.find("=") == std::string::npos) { + std::string DefaultValue = + GetDefaultValueString(Param, PP.getSourceManager(), PP.getLangOpts()); + if (!DefaultValue.empty()) + PlaceholderStr += " = " + DefaultValue; + } if (Function->isVariadic() && P == N - 1) PlaceholderStr += ", ..."; @@ -3012,10 +3034,18 @@ // Format the placeholder string. std::string Placeholder; - if (Function) - Placeholder = FormatFunctionParameter(Policy, Function->getParamDecl(P)); - else + if (Function) { + const ParmVarDecl *Param = Function->getParamDecl(P); + Placeholder = FormatFunctionParameter(Policy, Param); + if (Param->hasDefaultArg() && Placeholder.find("=") == std::string::npos) { + std::string DefaultValue = + GetDefaultValueString(Param, Context.getSourceManager(), Context.getLangOpts()); + if (!DefaultValue.empty()) + Placeholder += " = " + DefaultValue; + } + } else { Placeholder = Prototype->getParamType(P).getAsString(Policy); + } if (P == CurrentArg) Result.AddCurrentParameterChunk(