This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Fix space in for-each macro definition.
ClosedPublic

Authored by strager on Jun 4 2015, 6:49 PM.

Details

Reviewers
djasper
Summary

The C preprocessor definition of a for-each macro was being
improperly formatted. A space was being inserted between the
macro name and the opening parenthesis. Fix the extra space
by excluding such cases from the ForEachMacros checks.

Diff Detail

Event Timeline

strager updated this revision to Diff 27169.Jun 4 2015, 6:49 PM
strager retitled this revision from to clang-format: Fix space in for-each macro definition.
strager updated this object.
strager edited the test plan for this revision. (Show Details)
strager added a reviewer: djasper.
strager added subscribers: abdulras, sas, Unknown Object (MLST).
djasper edited edge metadata.Jun 5 2015, 1:08 AM

Please use unittests/Format/FormatTest.cpp for the unit test.

lib/Format/Format.cpp
1130–1131

Generally use clang-format. Also, why are you using two nested if conditions instead of just merging this into the other one?

strager planned changes to this revision.Jun 8 2015, 7:02 PM

Please use unittests/Format/FormatTest.cpp for the unit test.

Okay. (Should the other tests be ported too? Is there something special about the tests currently in test/Format?)

lib/Format/Format.cpp
1130–1131

I'll merge them.

The fundamental difference is that the tests in test/Format verify the behavior of the clang-format binary, e.g. with regard to certain command line flags, etc.

You are testing a specific formatting behavior (of the clang-format library), which is done in unittests/Format.

strager updated this revision to Diff 27470.Jun 10 2015, 3:43 PM
strager retitled this revision from clang-format: Fix space in for-each macro definition to clang-format: Fix space in for-each macro definition..
strager edited edge metadata.

Move tests into FormatTest.

I got this message from arc diff:

Invalid Content Encoding (Non-UTF8)
This diff includes a file which is not valid UTF-8 (it has invalid byte
sequences). You can either stop this workflow and fix it, or continue. If you
continue, this file will be marked as binary.

You can learn more about how Phabricator handles character encodings (and how
to configure encoding settings and detect and correct encoding problems) by
reading 'User Guide: UTF-8 and Character Encoding' in the Phabricator
documentation.

    AFFECTED FILE
    unittests/Format/FormatTest.cpp

    Do you want to mark this file as binary and continue? [Y/n]

That's why unittests/Format/FormatTest.cpp is marked as binary. *sigh*

Here's the git-diff:

diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 69d6cee..0c45f3b 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -610,12 +610,20 @@ TEST_F(FormatTest, RangeBasedForLoops) {
 }

 TEST_F(FormatTest, ForEachLoops) {
+  verifyFormat("#define foreach(x, y)\n"
+               "#define Q_FOREACH(x, y)\n"
+               "#define BOOST_FOREACH(x, y)\n"
+               "#define UNKNOWN_FOREACH(x, y)\n");
   verifyFormat("void f() {\n"
                "  foreach (Item *item, itemlist) {}\n"
                "  Q_FOREACH (Item *item, itemlist) {}\n"
                "  BOOST_FOREACH (Item *item, itemlist) {}\n"
                "  UNKNOWN_FORACH(Item * item, itemlist) {}\n"
                "}");
+  verifyFormat("#define foreach (x, y)\n"
+               "#define Q_FOREACH (x, y)\n"
+               "#define BOOST_FOREACH (x, y)\n"
+               "#define UNKNOWN_FOREACH (x, y)\n");
 }

 TEST_F(FormatTest, FormatsWhileLoop) {
djasper accepted this revision.Jun 11 2015, 1:44 AM
djasper edited edge metadata.

The patch looks good and I have submitted it as r239513 (didn't know whether you have commit access).

However, we cannot reproduce FormatTest.cpp being treated as binary. We have tried with git and svn and looked at whether there might be something wrong with phabricator, but everything seems fine. Can you try to create proper patches for all of you other changes? If it doesn't work with ARC, can you just use the Web interface to upload the patches (ideally created with full-file context)? Thanks.

This revision is now accepted and ready to land.Jun 11 2015, 1:44 AM
djasper closed this revision.Jun 11 2015, 1:48 AM

I understand why you cannot reproduce the arc diff problem. Facebook has a(n unpublished) change in arc which blocks non-BMP code points from being uploaded in a diff. (I'm using Facebook's arc.) FormatTest.cpp contains Japanese characters, which lie outside the BMP.

This isn't a problem with LLVM's Phabricator setup; it's a problem with my setup.