<div dir="ltr">So apparently clang-format uses the current behavior where the optionals aren't initialized if they're missing to parse the formatting styles that are based on other styles. <div><br></div><div>I think it would be easier to just change the documentation for YAML to say that it doesn't initialize the optional values that don't have a default value if they are missing in the mapping.</div><div><br></div><div>Thoughts?</div><div>Alex</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-06-17 14:45 GMT-07:00 Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On 2015 Jun 16, at 16:37, Alex Lorenz <<a href="mailto:arphaman@gmail.com">arphaman@gmail.com</a>> wrote:<br>
><br>
> Hi dexonsmith, bob.wilson, bogner,<br>
><br>
> This patch ensures that a value that's passed into YAML's IO mapOptional method is going to be assigned a value returned by the default constructor when the appropriate key is not present in the YAML mapping.<br>
><br>
> The current YAML documentation specifies that this should happen: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_YamlIO.html-23default-2Dvalues&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=nQsYTkqno5ZMb-NK9FlAyEW2He0E-qpzZjm7PgANB7c&s=1uXEoymEgMqnbnjNw7186wqJWGSOARb-Q5_ztbBR3no&e=" rel="noreferrer" target="_blank">http://llvm.org/docs/YamlIO.html#default-values</a><br>
<br>
</span>LGTM.<br>
<div><div class="h5"><br>
><br>
> REPOSITORY<br>
> rL LLVM<br>
><br>
> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10492&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=nQsYTkqno5ZMb-NK9FlAyEW2He0E-qpzZjm7PgANB7c&s=7GG4l4XP83Cr1PLHUINQfPx2i1yLhn5q1lvgWQWQZoc&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/D10492</a><br>
><br>
> Files:<br>
> include/llvm/Support/YAMLTraits.h<br>
> unittests/Support/YAMLIOTest.cpp<br>
><br>
> Index: include/llvm/Support/YAMLTraits.h<br>
> ===================================================================<br>
> --- include/llvm/Support/YAMLTraits.h<br>
> +++ include/llvm/Support/YAMLTraits.h<br>
> @@ -647,6 +647,8 @@<br>
> if ( this->preflightKey(Key, Required, false, UseDefault, SaveInfo) ) {<br>
> yamlize(*this, Val, Required);<br>
> this->postflightKey(SaveInfo);<br>
> + } else if (UseDefault) {<br>
> + Val = T();<br>
> }<br>
> }<br>
><br>
> Index: unittests/Support/YAMLIOTest.cpp<br>
> ===================================================================<br>
> --- unittests/Support/YAMLIOTest.cpp<br>
> +++ unittests/Support/YAMLIOTest.cpp<br>
> @@ -68,6 +68,21 @@<br>
> }<br>
> }<br>
><br>
> +struct FooBarOptional {<br>
> + int Foo;<br>
> + int Bar;<br>
> +};<br>
> +<br>
> +namespace llvm {<br>
> +namespace yaml {<br>
> +template <> struct MappingTraits<FooBarOptional> {<br>
> + static void mapping(IO &YamlIO, FooBarOptional &Obj) {<br>
> + YamlIO.mapRequired("foo", Obj.Foo);<br>
> + YamlIO.mapOptional("bar", Obj.Bar);<br>
> + }<br>
> +};<br>
> +}<br>
> +}<br>
><br>
> //<br>
> // Test the reading of a yaml mapping<br>
> @@ -93,6 +108,19 @@<br>
> }<br>
> }<br>
><br>
> +TEST(YAMLIO, TestMapReadOptional) {<br>
> + FooBarOptional Doc;<br>
> + Doc.Bar = 42;<br>
> + {<br>
> + Input In("---\nfoo: 3\n...\n");<br>
> + In >> Doc;<br>
> +<br>
> + EXPECT_FALSE(In.error());<br>
> + EXPECT_EQ(Doc.Foo, 3);<br>
> + EXPECT_EQ(Doc.Bar, 0);<br>
> + }<br>
> +}<br>
> +<br>
> TEST(YAMLIO, TestMalformedMapRead) {<br>
> FooBar doc;<br>
> Input yin("{foo: 3; bar: 5}", nullptr, suppressErrorMessages);<br>
><br>
> EMAIL PREFERENCES<br>
> <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_settings_panel_emailpreferences_&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=nQsYTkqno5ZMb-NK9FlAyEW2He0E-qpzZjm7PgANB7c&s=zw3iLpL7RzIMYVAcbMfFGk1zH624_e-8GQSxnT9fXWY&e=" rel="noreferrer" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
</div></div>> <D10492.27793.patch><br>
<br>
</blockquote></div><br></div>