[PATCH] D33644: Add default values for function parameter chunks

Ivan Donchevskii via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 19 02:16:14 PDT 2017


yvvan added inline comments.


================
Comment at: lib/Sema/SemaCodeComplete.cpp:2453
     std::string PlaceholderStr = FormatFunctionParameter(Policy, Param);
+    if (Param->hasDefaultArg() && PlaceholderStr.find("=") == std::string::npos) {
+        std::string DefaultValue =
----------------
klimek wrote:
> yvvan wrote:
> > klimek wrote:
> > > yvvan wrote:
> > > > klimek wrote:
> > > > > Why the check for = in the PlaceholderStr?
> > > > Not to add default value twice. If there's already "=" in placeholder string that means we've already added it in FormatFunctionParameter call
> > > In which cases would the default value not be added in FormatFunctionParameter if there is one, and need to be added here?
> > If Param->evaluateValue() can evaluate it it will set the default value in FormatFunctionParameter (that means it's a primitive type like "void func(int i = 0)").
> > In case it's some kind of non-primitive type like "void func(Foo foo = Foo(0, 0))" it will not be evaluated and we can use here the source manager to get the default value string. In this example it will be Foo(0, 0).
> Why don't we always add it in the unevaluated form? I'd expect constants from macros are useful to see unevaluated?
Hm, after using Lexer::getSourceText that makes sense! I had some issues getting source parts on my own without evaluation in some complicated cases with macros usage, etc.
I will test the solution without evaluation and update diff here if nothing breaks.


https://reviews.llvm.org/D33644





More information about the cfe-commits mailing list