0

I am ramping up a Platform IO project. Within there I am using clang-tidy for different checks (see documentation for PIO clang-tidy here).

Given the folder structure

- .
-- include
-- src

I placed a header file in the include folder, called ISomeInterface.h The content looks like this:

#pragma once

namespace some_namespace { // interface declaration
}

When I run pio check (invokes clang-tidy) I get the warning

variable 'some_namespace' is non-const and globally accessible, consider making it const  [cppcoreguidelines-avoid-non-const-global-variables]

The Question is: Why is CLang not recognizing the namespace keyword? I found a possible solution here SO Thread that states

can't use clang-tidy directly on header files. Instead i have to check the cpp file and have to add -header-filter=.* to also check the headers

But this did not work for me :(

stev-e
  • 436
  • 6
  • 15
  • Can you share exact command with which `clang-tidy` is invoked? I don't know PIO, but it should be somewhere in the logs. (My blind guess is for some reason clang-tidy is treating your header as C source, not C++) – R2RT Feb 18 '22 at 13:22
  • Hi, I just recognized the option to output some information via clangtidy flag -export-fixes=.fixes.txt Now there I can see the error "clang 'unknown type name ''namespace''"' just before the user visible warning "variable 'some_namespace' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]". That sounds like a c<>c++ problem to me as well. I will check that. – stev-e Feb 18 '22 at 13:41

0 Answers0