mprobst / ClangFormatIJ

clang-format for IntelliJ based IDEs
Apache License 2.0
15 stars 9 forks source link

Incorrect behavior on files with non-ascii symbols #13

Open SX91 opened 5 years ago

SX91 commented 5 years ago
#include <ostream>

struct A {};

// And here we go insane! И вот с этого места всё накрылось.

struct B {
    int    a;
};

int main(void)
{
    std::cout << "hello, world!\n";
    return 0;
}

If you'd try to format the above code with the plugin, you'll see the file content gets destroyed.


#include <ostream>

struct A
{};

// And here we go insane! И вот с этого места всё накрылось.

struct B {
    int    a;
};

int ma
n(void)
{  std::cout << "hello, world!\n";
    return 0;
}

CLion 2018.3.2, latest plugin from marketplace.

alexkaratarakis commented 5 years ago

Here is another instance where Unicode characters cause problems:

/**
 * � 
 */

#define foo 0  // Some comments
#define BAR 1   // Yet another comment
#define BAZ_foo 2     // Even more comments

Select all of it, right click, Reformat current Statement with clang format:

/**
 * � 

#define foo 0         Some comments
#define BAR 1         Yet another comment
#define BAZ_foo 2     Even more comments

Another example:

/**
 * �
 */

#define FOO      0       // Comments
#define BAR      1       // More comments
#define BAZ      2       // Even more

becomes:

/**
 * �
 */

#define FOO       Comments
#define BAR       More comments
#define BAZ       Even more

edit: CLion 2018.3.2, plugin v1.1.0

fgr commented 5 years ago

Same problem here:

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
// in one cpp file
#include "catch.hpp"

SCENARIO("Artikel können in Lager geliefert werden", "[Lagerverwaltung]") {

  GIVEN("eine leere Lagerverwaltung") {
    //Lagerverwaltung lager;

    //REQUIRE( lager.lagerbestand().empty() );
    REQUIRE(true);

    // lager.anlieferung_buchen({"test", 42});

    // lager.anlieferung_buchen({"test", 42});

    //    auto const lieferbar = lager.ist_lieferbar({"test", -1});
  }
}

becomes

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this
// in one cpp file
#include "catch.hpp"

SCENARIO("Artikel können in Lager geliefert werden", "[Lagerverwaltung]") {

  GIVEN("eine leere Lagerverwaltung") {

    /L agerverwaltung lager;

    //R EQUIRE( lager.lagerbestand().empty() );
    REQUIRE(true);

    // lager.anlieferung_buchen({"test", 42});

    / lager.anlieferung_buchen({"test", 42});

    /    auto const lieferbar = lager.ist_lieferbar({"test", -1});
  }
}

I'm using CLion 2018.3.4 on macOS. The plugin version is v1.1.0.

wangzw commented 4 years ago

The root cause is that clang-format accept BYTE offset as input, but the plugin pass in char offset.