ABSL_FLAG macro triggers abseil-no-namespace check
alokpr opened this issue · comments
Describe the bug
ABSL_FLAG triggers clang-tidy abseil-no-namespace check
Steps to reproduce the bug
$ cat main.cc
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
ABSL_FLAG(std::string, input, "input", "input file path");
int main(int argc, char* argv[]) {
absl::ParseCommandLine(argc, argv);
return EXIT_SUCCESS;
}
clang-tidy --checks=abseil-* main.cc
main.cc:7:1: error: namespace 'absl' is reserved for implementation of the Abseil library and should not be opened in user code [abseil-no-namespace,-warnings-as-errors]
ABSL_FLAG(std::string, input, "input", "input file path");
^
external/com_google_absl/absl/flags/flag.h:166:3: note: expanded from macro 'ABSL_FLAG'
ABSL_FLAG_IMPL(Type, name, default_value, help)
^
external/com_google_absl/absl/flags/flag.h:269:13: note: expanded from macro 'ABSL_FLAG_IMPL'
namespace absl /* block flags in namespaces */ {} \
^
What version of Abseil are you using?
What operating system and version are you using
Ubuntu 18.04
What compiler and version are you using?
clang-tidy-13
What build system are you using?
bazel 4.2.2
The Abseil library is working correctly in this case. ABSL_FLAG needs to be exempted from the clang-tidy check. I'll need to track down someone who can make the change to clang-tidy.
This bug just got more interesting because with the new Abseil logging projects can reasonably attempt to switch from glog/gflags to the Abseil equivalents.
Workaround: put this, or something like it, in your project's .clang-tidy
file:
Checks: 'abseil-*,-abseil-no-namespace'