clang-tools
20.0.0git
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
z
Typedefs
a
b
c
d
f
g
h
i
n
o
p
q
r
s
t
u
Enumerations
b
c
d
e
f
h
i
j
l
m
n
o
p
q
r
s
t
u
v
w
Enumerator
a
b
c
d
e
f
h
l
m
n
o
p
q
r
s
t
u
v
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
~
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
Typedefs
a
c
d
e
f
h
i
j
k
l
m
n
o
p
r
s
t
v
w
Enumerations
a
b
c
d
e
f
h
i
k
l
m
n
p
q
r
s
u
Enumerator
a
b
c
d
e
f
g
h
i
k
m
n
o
p
q
r
s
t
u
v
Related Functions
:
c
d
h
i
l
o
p
r
Files
File List
File Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
x
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Typedefs
Enumerations
Enumerator
Macros
a
c
d
e
f
h
m
n
o
p
r
s
t
llvm-project
clang-tools-extra
clang-tidy
google
UnnamedNamespaceInHeaderCheck.cpp
Go to the documentation of this file.
1
//===--- UnnamedNamespaceInHeaderCheck.cpp - clang-tidy ---------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "
UnnamedNamespaceInHeaderCheck.h
"
10
#include "clang/AST/ASTContext.h"
11
#include "clang/ASTMatchers/ASTMatchFinder.h"
12
#include "clang/ASTMatchers/ASTMatchers.h"
13
14
using namespace
clang::ast_matchers
;
15
16
namespace
clang::tidy::google::build
{
17
18
UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck
(
19
StringRef
Name
,
ClangTidyContext
*Context)
20
:
ClangTidyCheck
(
Name
, Context),
21
HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
22
23
void
UnnamedNamespaceInHeaderCheck::registerMatchers
(
24
ast_matchers::MatchFinder *Finder) {
25
Finder->addMatcher(namespaceDecl(isAnonymous()).bind(
"anonymousNamespace"
),
26
this
);
27
}
28
29
void
UnnamedNamespaceInHeaderCheck::check
(
30
const
MatchFinder::MatchResult &Result) {
31
const
auto
*N = Result.Nodes.getNodeAs<NamespaceDecl>(
"anonymousNamespace"
);
32
SourceLocation
Loc
= N->getBeginLoc();
33
if
(!
Loc
.isValid())
34
return
;
35
36
if
(
utils::isPresumedLocInHeaderFile
(
Loc
, *Result.SourceManager,
37
HeaderFileExtensions))
38
diag
(
Loc
,
"do not use unnamed namespaces in header files"
);
39
}
40
41
}
// namespace clang::tidy::google::build
Name
llvm::SmallString< 256U > Name
Definition:
ChainedComparisonCheck.cpp:42
Loc
SourceLocation Loc
Definition:
KernelNameRestrictionCheck.cpp:44
UnnamedNamespaceInHeaderCheck.h
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:53
clang::tidy::ClangTidyCheck::diag
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Definition:
ClangTidyCheck.cpp:25
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:69
clang::tidy::google::build::UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck
UnnamedNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context)
Definition:
UnnamedNamespaceInHeaderCheck.cpp:18
clang::tidy::google::build::UnnamedNamespaceInHeaderCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
UnnamedNamespaceInHeaderCheck.cpp:29
clang::tidy::google::build::UnnamedNamespaceInHeaderCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
UnnamedNamespaceInHeaderCheck.cpp:23
clang::ast_matchers
Definition:
AbseilMatcher.h:13
clang::tidy::google::build
Definition:
ExplicitMakePairCheck.cpp:23
clang::tidy::utils::isPresumedLocInHeaderFile
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether presumed location of Loc is in header file.
Definition:
FileExtensionsUtils.cpp:22
Generated on Tue Mar 11 2025 11:24:56 for clang-tools by
1.9.6