Giter Site home page Giter Site logo

Comments (16)

Kypert avatar Kypert commented on May 24, 2024 2

Seems to work for me, if you just switch to lower-case c++14 instead:

let g:clang_format#style_options = {
            \ "AccessModifierOffset" : -4,
            \ "Standard" : "c++14"}

(Looks like upper-case C was regarded as legacy after C++11: https://github.com/llvm-mirror/clang/blob/65acf43270ea2894dffa0d0b292b92402f80c8cb/lib/Format/Format.cpp#L77)

Can you confirm?

from vim-clang-format.

Kypert avatar Kypert commented on May 24, 2024 1

To me it looks like the version of clang-format you use do not include the commit I mentioned. Are you using 9.0.1? If I am reading it correctly, you need 10.0.0-rc1 to get the c++14 attribute.

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024 1

@Kypert , I just followed your suggestion to scale down. Found that set tabstop=4 and set shiftwidth=4 vim .vimrc is the root cause. Thanks a million.

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024

Seems no activity in this repo. I have reverted to clang-format.py solution. So far so good.
map <C-K> :py3file /usr/share/clang/clang-format.py<cr>

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024

@Kypert Confirmed that only when g:clang_format#style_options is removed, ClangFormat will work. Lower case does not work for me either. Sad

from vim-clang-format.

Kypert avatar Kypert commented on May 24, 2024

Perhaps you can obtain more clear information by running: :ClangFormatEchoFormattedCode

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024

@Kypert Cool. It's clear now. But I do not know how to fix. Could you throw some light upon this?

YAML:1:91: error: unknown enumerated scalar
{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++14'}
                                                                                          ^~~~~~~
Error parsing -style: Invalid argument

from vim-clang-format.

Kypert avatar Kypert commented on May 24, 2024

Thank you for the output. Could you please share the version of the clang-format that you are trying to invoke? Did you point to a certain version via g:clang_format#command?

Could it be that you are using a version of clang-format that does not include llvm/llvm-project@e503256?

You can also try to run the command manually with your style, to isolate the problem:

> echo test > testfile
> clang-format --style="{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++14'}" -- testfile
test

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024

Tried your test case, but it failed to format.
I am using Arch Linux. clang-format is provided by package clang. llvm
is also installed.

➜  ~ cat testfile
test
➜  ~ clang-format --style="{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++14'}" -- testfile
YAML:1:91: error: unknown enumerated scalar
{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++14'}
                                                                                          ^~~~~~~
Error parsing -style: Invalid argument
➜  ~ 

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024

Even if I changed Standard to c++11, the same error occurred. But upper case C++11 works!

clang-format --style="{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++11'}" -- testfile
YAML:1:91: error: unknown enumerated scalar
{BasedOnStyle: google, IndentWidth: 4, UseTab: true, AccessModifierOffset: '-4',Standard: 'c++11'}
                                                                                          ^~~~~~~
Error parsing -style: Invalid argument

from vim-clang-format.

Kypert avatar Kypert commented on May 24, 2024

But upper case C++11 works!

Makes sense, since the lower-case versions were added in the commit I mentioned. I think we have a case-closed situations :) Please update your clang-format binary or adapt the config.

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024

There is another problem that I didn't mention earlier. Invoking :ClangFormat from vim doesn't format the code correctly. While clang-format command line works. The incorrect format result is as follows. You can see that the indentation of line 107 is wrong. I didn't set g:clang_format#style_options in .vimrc

int main() {
 99     std::vector<float> nums(10);
100     std::copy(nums.begin(), nums.end(),
101           std::ostream_iterator<float>(cout, " "));
102     cout << '\n';
103     return 0;
104     Solution solution;
105     std::string digits;
106     while (std::getline(cin, digits)) {
107     cout << solution.digitsToChinese(digits) << endl;
108     }

from vim-clang-format.

Kypert avatar Kypert commented on May 24, 2024

Sorry, not sure how to tackle that one. Like you said, it is another problem indeed, maybe check :ClangFormatEchoFormattedCode? Can you see if other parts of the code get formatted, like if you introduce extra spaces on other lines?

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024

Surprised. :ClangFormatEchoFormattedCode shows rightly formatted code. Quite confused now :P

from vim-clang-format.

Kypert avatar Kypert commented on May 24, 2024

Could it be that another plugin is interfering, would it be possible to scale down and see if the issue goes away at some point? Maybe you already solved it?

from vim-clang-format.

372046933 avatar 372046933 commented on May 24, 2024

Upgraded to clang 10.0.0-2, now Standard" : "c++17" is recognized.

from vim-clang-format.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.