Skip to content

Commit 47bd223

Browse files
authored
Merge branch 'main' into users/kparzysz/type-identity
2 parents e381f60 + 6a57af8 commit 47bd223

File tree

341 files changed

+6696
-4667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

341 files changed

+6696
-4667
lines changed

.github/copilot-instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
When performing a code review, pay close attention to code modifying a function's
2+
control flow. Could the change result in the corruption of performance profile
3+
data? Could the change result in invalid debug information, in particular for
4+
branches and calls?

clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder *Finder) {
120120
equalsBoundNode("param"), equalsBoundNode("var")))))),
121121
CapturedInLambda)),
122122
callee(unresolvedLookupExpr(hasAnyDeclaration(
123-
namedDecl(hasUnderlyingDecl(hasName("::std::forward")))))),
123+
namedDecl(hasUnderlyingDecl(hasName(ForwardFunction)))))),
124124

125125
unless(anyOf(hasAncestor(typeLoc()),
126126
hasAncestor(expr(hasUnevaluatedContext())))));
@@ -149,4 +149,13 @@ void MissingStdForwardCheck::check(const MatchFinder::MatchResult &Result) {
149149
<< Param;
150150
}
151151

152+
MissingStdForwardCheck::MissingStdForwardCheck(StringRef Name,
153+
ClangTidyContext *Context)
154+
: ClangTidyCheck(Name, Context),
155+
ForwardFunction(Options.get("ForwardFunction", "::std::forward")) {}
156+
157+
void MissingStdForwardCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
158+
Options.store(Opts, "ForwardFunction", ForwardFunction);
159+
}
160+
152161
} // namespace clang::tidy::cppcoreguidelines

clang-tools-extra/clang-tidy/cppcoreguidelines/MissingStdForwardCheck.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ namespace clang::tidy::cppcoreguidelines {
2121
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/missing-std-forward.html
2222
class MissingStdForwardCheck : public ClangTidyCheck {
2323
public:
24-
MissingStdForwardCheck(StringRef Name, ClangTidyContext *Context)
25-
: ClangTidyCheck(Name, Context) {}
24+
MissingStdForwardCheck(StringRef Name, ClangTidyContext *Context);
2625
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2726
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2827
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
@@ -31,6 +30,10 @@ class MissingStdForwardCheck : public ClangTidyCheck {
3130
std::optional<TraversalKind> getCheckTraversalKind() const override {
3231
return TK_IgnoreUnlessSpelledInSource;
3332
}
33+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
34+
35+
private:
36+
const StringRef ForwardFunction;
3437
};
3538

3639
} // namespace clang::tidy::cppcoreguidelines

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ Changes in existing checks
212212
<clang-tidy/checks/cppcoreguidelines/avoid-goto>` check by adding the option
213213
`IgnoreMacros` to ignore ``goto`` labels defined in macros.
214214

215+
- Improved :doc:`cppcoreguidelines-missing-std-forward
216+
<clang-tidy/checks/cppcoreguidelines/missing-std-forward>` check by adding a
217+
flag to specify the function used for forwarding instead of ``std::forward``.
218+
215219
- Improved :doc:`cppcoreguidelines-special-member-functions
216220
<clang-tidy/checks/cppcoreguidelines/special-member-functions>` check by
217221
adding the option `IgnoreMacros` to ignore classes defined in macros.

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/missing-std-forward.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ Example:
3535
f(1, 2); // Incorrect - may not invoke the desired qualified function operator
3636
}
3737

38+
Options
39+
-------
40+
41+
.. option:: ForwardFunction
42+
43+
Specify the function used for forwarding. Default is `::std::forward`.
44+
3845
This check implements `F.19
3946
<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-forward>`_
4047
from the C++ Core Guidelines.

clang-tools-extra/test/clang-doc/json/class.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ struct MyClass {
2323
typedef int MyTypedef;
2424

2525
class NestedClass;
26+
27+
friend struct Foo;
28+
template<typename T> friend void friendFunction(int);
2629
protected:
2730
int protectedMethod();
2831

@@ -86,6 +89,44 @@ struct MyClass {
8689
// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"
8790
// CHECK-NEXT: }
8891
// CHECK-NEXT: ],
92+
// CHECK-NOT: "Friends": [
93+
// CHECK-NOT: {
94+
// CHECK-NOT: "IsClass": false,
95+
// CHECK-NOT: "Params": [
96+
// CHECK-NOT: {
97+
// CHECK-NOT: "Name": "",
98+
// CHECK-NOT: "Type": "int"
99+
// CHECK-NOT: }
100+
// CHECK-NOT: ],
101+
// CHECK-NOT: "Reference": {
102+
// CHECK-NOT: "Name": "friendFunction",
103+
// CHECK-NOT: "Path": "",
104+
// CHECK-NOT: "QualName": "friendFunction",
105+
// CHECK-NOT: "USR": "{{[0-9A-F]*}}"
106+
// CHECK-NOT: },
107+
// CHECK-NOT: "ReturnType": {
108+
// CHECK-NOT: "IsBuiltIn": true,
109+
// CHECK-NOT: "IsTemplate": false,
110+
// CHECK-NOT: "Name": "void",
111+
// CHECK-NOT: "QualName": "void",
112+
// CHECK-NOT: "USR": "0000000000000000000000000000000000000000"
113+
// CHECK-NOT: },
114+
// CHECK-NOT: "Template": {
115+
// CHECK-NOT: "Parameters": [
116+
// CHECK-NOT: "typename T"
117+
// CHECK-NOT: ]
118+
// CHECK-NOT: }
119+
// CHECK-NOT: },
120+
// CHECK-NOT: {
121+
// CHECK-NOT: "IsClass": true,
122+
// CHECK-NOT: "Reference": {
123+
// CHECK-NOT: "Name": "Foo",
124+
// CHECK-NOT: "Path": "GlobalNamespace",
125+
// CHECK-NOT: "QualName": "Foo",
126+
// CHECK-NOT: "USR": "{{[0-9A-F]*}}"
127+
// CHECK-NOT: },
128+
// CHECK-NOT: },
129+
// CHECK-NOT: ],
89130
// COM: FIXME: FullName is not emitted correctly.
90131
// CHECK-NEXT: "FullName": "",
91132
// CHECK-NEXT: "IsTypedef": false,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %check_clang_tidy -std=c++14 %s cppcoreguidelines-missing-std-forward %t -- \
2+
// RUN: -config="{CheckOptions: {cppcoreguidelines-missing-std-forward.ForwardFunction: custom_forward}}" -- -fno-delayed-template-parsing
3+
4+
// NOLINTBEGIN
5+
namespace std {
6+
7+
template <typename T> struct remove_reference { using type = T; };
8+
template <typename T> struct remove_reference<T&> { using type = T; };
9+
template <typename T> struct remove_reference<T&&> { using type = T; };
10+
11+
template <typename T> using remove_reference_t = typename remove_reference<T>::type;
12+
13+
template <typename T> constexpr T &&forward(remove_reference_t<T> &t) noexcept;
14+
template <typename T> constexpr T &&forward(remove_reference_t<T> &&t) noexcept;
15+
template <typename T> constexpr remove_reference_t<T> &&move(T &&x);
16+
17+
} // namespace std
18+
// NOLINTEND
19+
20+
template<class T>
21+
constexpr decltype(auto) custom_forward(std::remove_reference_t<T>& tmp) noexcept
22+
{
23+
return static_cast<T&&>(tmp);
24+
}
25+
26+
template<class T>
27+
constexpr decltype(auto) custom_forward(std::remove_reference_t<T>&& tmp) noexcept
28+
{
29+
return static_cast<T&&>(tmp);
30+
}
31+
32+
template<class T>
33+
void forward_with_std(T&& t) {
34+
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: forwarding reference parameter 't' is never forwarded inside the function body [cppcoreguidelines-missing-std-forward]
35+
36+
T other{std::forward<T>(t)};
37+
}
38+
39+
template<class T>
40+
void move_with_custom(T&& t) {
41+
T other{custom_forward<T>(t)};
42+
}

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,6 @@ Improvements to Clang's diagnostics
655655
#GH69470, #GH59391, #GH58172, #GH46215, #GH45915, #GH45891, #GH44490,
656656
#GH36703, #GH32903, #GH23312, #GH69874.
657657

658-
- A warning is now emitted when ``main`` is attached to a named module,
659-
which can be turned off with ``-Wno-main-attached-to-named-module``. (#GH146247)
660-
661658
- Clang now avoids issuing `-Wreturn-type` warnings in some cases where
662659
the final statement of a non-void function is a `throw` expression, or
663660
a call to a function that is trivially known to always throw (i.e., its
@@ -901,7 +898,9 @@ Bug Fixes to AST Handling
901898
- Fixed a malformed printout of ``CXXParenListInitExpr`` in certain contexts.
902899
- Fixed a malformed printout of certain calling convention function attributes. (#GH143160)
903900
- Fixed dependency calculation for TypedefTypes (#GH89774)
901+
- The ODR checker now correctly hashes the names of conversion operators. (#GH143152)
904902
- Fixed the right parenthesis source location of ``CXXTemporaryObjectExpr``. (#GH143711)
903+
- Fixed a crash when performing an ``IgnoreUnlessSpelledInSource`` traversal of ASTs containing ``catch(...)`` statements. (#GH146103)
905904

906905
Miscellaneous Bug Fixes
907906
^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ASTNodeTraverser
9999
TraversalKind GetTraversalKind() const { return Traversal; }
100100

101101
void Visit(const Decl *D, bool VisitLocs = false) {
102-
if (Traversal == TK_IgnoreUnlessSpelledInSource && D->isImplicit())
102+
if (Traversal == TK_IgnoreUnlessSpelledInSource && D && D->isImplicit())
103103
return;
104104

105105
getNodeDelegate().AddChild([=] {

clang/include/clang/AST/ODRHash.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ class ODRHash {
9696
void AddNestedNameSpecifier(const NestedNameSpecifier *NNS);
9797
void AddDependentTemplateName(const DependentTemplateStorage &Name);
9898
void AddTemplateName(TemplateName Name);
99-
void AddDeclarationName(DeclarationName Name, bool TreatAsDecl = false);
99+
void AddDeclarationNameInfo(DeclarationNameInfo NameInfo,
100+
bool TreatAsDecl = false);
101+
void AddDeclarationName(DeclarationName Name, bool TreatAsDecl = false) {
102+
AddDeclarationNameInfo(DeclarationNameInfo(Name, SourceLocation()),
103+
TreatAsDecl);
104+
}
105+
100106
void AddTemplateArgument(TemplateArgument TA);
101107
void AddTemplateParameterList(const TemplateParameterList *TPL);
102108

@@ -108,7 +114,7 @@ class ODRHash {
108114
static bool isSubDeclToBeProcessed(const Decl *D, const DeclContext *Parent);
109115

110116
private:
111-
void AddDeclarationNameImpl(DeclarationName Name);
117+
void AddDeclarationNameInfoImpl(DeclarationNameInfo NameInfo);
112118
};
113119

114120
} // end namespace clang

0 commit comments

Comments
 (0)