Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -2351,6 +2351,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, @@ -2379,11 +2386,17 @@ FirstParameter = false; else Result.AddChunk(CodeCompletionString::CK_Comma); - + InOptional = false; // Format the placeholder string. std::string PlaceholderStr = FormatFunctionParameter(Policy, Param); + if (Param->hasDefaultArg()) { + std::string DefaultValue = + GetDefaultValueString(Param, PP.getSourceManager(), PP.getLangOpts()); + if (!DefaultValue.empty() && DefaultValue != "=") + PlaceholderStr += " = " + DefaultValue; + } if (Function->isVariadic() && P == N - 1) PlaceholderStr += ", ..."; @@ -2964,10 +2977,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()) { + std::string DefaultValue = + GetDefaultValueString(Param, Context.getSourceManager(), Context.getLangOpts()); + if (!DefaultValue.empty() && DefaultValue != "=") + Placeholder += " = " + DefaultValue; + } + } else { Placeholder = Prototype->getParamType(P).getAsString(Policy); + } if (P == CurrentArg) Result.AddCurrentParameterChunk(