Skip to content

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

@KangarooKoala

Description

@KangarooKoala

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions