<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - TextProto RawStringFormats misbehaves when also specified as top-level language"
   href="https://bugs.llvm.org/show_bug.cgi?id=42786">42786</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>TextProto RawStringFormats misbehaves when also specified as top-level language
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Formatter
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>alex@xnor.ai
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>