Skip to content

clang-format adds a space between the parameter type and & under google style guide #164866

@PiJoules

Description

@PiJoules

Here's a regression test demonstrating this:

// RUN: grep -Ev "// *[A-Z-]+" %s | clang-format --style='{BasedOnStyle: google, ColumnLimit: 0}' | FileCheck %s -strict-whitespace

// CHECK: ::test_anonymous::FunctionApplication& ::test_anonymous::FunctionApplication::operator=(const ::test_anonymous::FunctionApplication& other) noexcept {
::test_anonymous::FunctionApplication& ::test_anonymous::FunctionApplication::operator=(const ::test_anonymous::FunctionApplication& other) noexcept {
  storage_ = other.CloneStorage_();
  return *this;
}

which fails with

# | /usr/local/google/home/leonardchan/llvm-projects/llvm-project-1/clang/test/Format/regression-test.cpp:3:11: error: CHECK: expected string not found in input
# | // CHECK: ::test_anonymous::FunctionApplication& ::test_anonymous::FunctionApplication::operator=(const ::test_anonymous::FunctionApplication& other) noexcept {
# |           ^
# | <stdin>:1:1: note: scanning from here
# | 
# | ^
# | <stdin>:2:1: note: possible intended match here
# | ::test_anonymous::FunctionApplication& ::test_anonymous::FunctionApplication::operator=(const ::test_anonymous::FunctionApplication & other) noexcept {
# | ^
# | 

The google style guide does not permit a space before the & as per https://google.github.io/styleguide/cppguide.html#Pointer_and_Reference_Expressions.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions