LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 41870 - Inconsistent behavior regarding line break before access modifier.
Summary: Inconsistent behavior regarding line break before access modifier.
Status: RESOLVED FIXED
Alias: None
Product: clang-tools-extra
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: PC other
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-14 06:49 PDT by Florian Gähr
Modified: 2021-04-21 00:51 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
Files to reproduce bug (473 bytes, application/x-7z-compressed)
2019-05-14 06:49 PDT, Florian Gähr
Details
Possible bugfix (1.21 KB, patch)
2021-03-29 06:14 PDT, Max Sagebaum
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Gähr 2019-05-14 06:49:38 PDT
Created attachment 21949 [details]
Files to reproduce bug

#Description

Inconsistent behavior regarding line break before access modifier.

If a newline exists it gets removed. If no newline exists it gets added.

Similar but not quite the same: https://bugs.llvm.org/show_bug.cgi?id=16518

#How to reproduce:
clang-format --style=file example.hpp > example_after.hpp


##.clang-format
MaxEmptyLinesToKeep: 0

##example.hpp
class a {
public:
  void b();
public: // newline gets inserted
  void c();

public: // newline gets removed
  void d();
}

##example_after.hpp
class a {
public:
  void b();

public: // newline gets inserted
  void c();
public: // newline gets removed
  void d();
}
Comment 1 Florian Gähr 2019-05-15 00:07:22 PDT
OS: Win10
Clang version: 8.0
Comment 2 Max Sagebaum 2021-03-29 06:14:45 PDT
Created attachment 24703 [details]
Possible bugfix

Reproduces on
OS: Fedora
Clang version: 11.0 and 12.0

The problem is that, Newlines is set to 1 because of the setting `MaxEmptyLinesToKeep`. The checks in the logic are based on `RootToken.NewlinesBefore` which is 2 and therefore Newlines is not changes. The checks need to be changed to the actual value of Newlines.

I will submit a merge request for the change.
Comment 3 Max Sagebaum 2021-03-29 06:44:17 PDT
Created a merge request for the fix.

https://reviews.llvm.org/D99503
Comment 4 Max Sagebaum 2021-04-21 00:51:33 PDT
Fixed via merge request https://reviews.llvm.org/D99503.