================
@@ -807,12 +807,18 @@ template <> struct MappingTraits<FormatStyle> {
         FormatStyle PredefinedStyle;
         if (getPredefinedStyle(StyleName, Style.Language, &PredefinedStyle) &&
             Style == PredefinedStyle) {
-          IO.mapOptional("# BasedOnStyle", StyleName);
+          // For convenience, emit the info which style this matches. However,
+          // setting BasedOnStyle will override all other keys when importing,
+          // so we set a helper key that is ignored when importing.
+          // Ideally, we'd want a YAML comment here, but that's not supported.
+          IO.mapOptional("OrigBasedOnStyle", StyleName);
----------------
jasilvanus wrote:

> I think clang-format will baff if there is styles in the .clang-format file 
> we don't understand, its very unforgiving of new styles

This will set a key that is never read just for reference, as the old comment 
did. 

> Why is using # not a valid YAML comment?

Using `#` in the textual yaml is a valid comment and perfectly fine. 
However, here we are using a function to set a key named `# BasedOnStyle`, which
just happened to emit a correct YAML comment because the key is not properly 
quoted/escaped.

This breaks when fixing key quoting. 

https://github.com/llvm/llvm-project/pull/89228
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to