Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper handling of C++ namespace comments in macros #279

Open
KangarooKoala opened this issue Jul 5, 2024 · 1 comment
Open

Improper handling of C++ namespace comments in macros #279

KangarooKoala opened this issue Jul 5, 2024 · 1 comment

Comments

@KangarooKoala
Copy link
Contributor

Given this input .cpp file:

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#define TEST(namespaceName, name, ...)\
  namespace namespaceName {\
  using name = __VA_ARGS__;\
  }  /* namespace namespacename */\
  using name = namespaceName::name;

Running wpiformat on the file results in this:

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#define TEST(namespaceName, name, ...) \
  namespace namespaceName {            \
  using name = __VA_ARGS__;            \
  }  // namespace namespaceName
using name = namespaceName::name;

It also happens on .h and .inc files (as long as there's an include guard or #pragma once) and with object-like macros.

It seems that in the BraceComment pipeline, wpiformat unconditionally uses a // comment to close a namespace, even though /* */ comments are also supposed to be clean for cpplint (for this very reason). Additionally, since there are no checks for NOLINT or NOLINTNEXTLINE in the pipeline, there is no way to suppress the format that I'm aware of.

@calcmogul
Copy link
Member

We force // for style reasons. /* */ should only be used when absolutely necessary. Detecting those cases properly may be difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants