[llvm-bugs] [Bug 42786] New: TextProto RawStringFormats misbehaves when also specified as top-level language

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 26 18:35:08 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42786

            Bug ID: 42786
           Summary: TextProto RawStringFormats misbehaves when also
                    specified as top-level language
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: alex at xnor.ai
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Consider the following .clang-format file:

Language: Cpp
BasedOnStyle: Google
RawStringFormats:
  - Language: TextProto
    Delimiters:
      - proto
    BasedOnStyle: Google
---
Language: TextProto
BasedOnStyle: Google

Then, consider the following C++ file (let's call it test.cc):

const char proto = R"proto(
message {
value: 1 }
)proto";

And, consider the following TextProto file (let's call it test.textpb):

message {
value: 1 }

With this configuration, I would expect the C++ file to be reformatted to:

const char proto = R"proto(
  message { value: 1 }
)proto";

And the TextProto file to be reformatted to:

message { value: 1 }

However, with the configuration file above, while the TextProto file is
formatted correctly, the C++ file is formatted with a very strange style:

const char proto = R"proto(
  message {value : 1}
)proto";

Observe the lack of spaces within the braces, and the extra space before the
colon.

If, however, this .clang-format file is used:

Language: Cpp
BasedOnStyle: Google
RawStringFormats:
  - Language: TextProto
    Delimiters:
      - proto
    BasedOnStyle: Google

(The only difference with the one above is that the TextProto language has been
removed at the top-level.)  Then formatting the C++ file yields the expected
output (but of course the TextProto file on its own can no longer be formatted
because "Configuration file(s) do(es) not support TextProto").

It does not seem right that adding an extra top-level language would affect the
formatting of the raw string, especially in this way.

I can reproduce this misbehavior with Clang 7.0.0 downloaded from
releases.llvm.org, Clang 8.0.0 downloaded from releases.llvm.org, and from
trunk built from SVN r367164.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190727/78cad662/attachment.html>


More information about the llvm-bugs mailing list