Skip to content

Commit 0a375ca

Browse files
authored
Merge branch 'llvm:main' into main
2 parents c611d08 + fc505d0 commit 0a375ca

File tree

98 files changed

+1876
-1379
lines changed

Some content is hidden

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

98 files changed

+1876
-1379
lines changed

clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ReplaceAutoPtrCheck : public ClangTidyCheck {
4242
public:
4343
ReplaceAutoPtrCheck(StringRef Name, ClangTidyContext *Context);
4444
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
45-
return LangOpts.CPlusPlus;
45+
return LangOpts.CPlusPlus11;
4646
}
4747
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
4848
void registerMatchers(ast_matchers::MatchFinder *Finder) override;

clang-tools-extra/clang-tidy/modernize/UseAutoCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class UseAutoCheck : public ClangTidyCheck {
1717
public:
1818
UseAutoCheck(StringRef Name, ClangTidyContext *Context);
1919
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
20-
return LangOpts.CPlusPlus;
20+
return LangOpts.CPlusPlus11;
2121
}
2222
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2323
void registerMatchers(ast_matchers::MatchFinder *Finder) override;

clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class UseEqualsDeleteCheck : public ClangTidyCheck {
2323
public:
2424
UseEqualsDeleteCheck(StringRef Name, ClangTidyContext *Context);
2525
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
26-
return LangOpts.CPlusPlus;
26+
return LangOpts.CPlusPlus11;
2727
}
2828
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2929
void registerMatchers(ast_matchers::MatchFinder *Finder) override;

clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ class UseNullptrCheck : public ClangTidyCheck {
1717
public:
1818
UseNullptrCheck(StringRef Name, ClangTidyContext *Context);
1919
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
20-
// FIXME this should be CPlusPlus11 but that causes test cases to
21-
// erroneously fail.
22-
return LangOpts.CPlusPlus || LangOpts.C23;
20+
return LangOpts.CPlusPlus11 || LangOpts.C23;
2321
}
2422
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
2523
void registerMatchers(ast_matchers::MatchFinder *Finder) override;

clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp

Lines changed: 31 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
// RUN: %check_clang_tidy -std=c++98 %s modernize-use-nullptr %t -- -- -Wno-non-literal-null-conversion
2-
//
3-
// Some parts of the test (e.g. assignment of `const int` to `int *`) fail in
4-
// C++11, so we need to run the test in C++98 mode.
5-
//
6-
// FIXME: Make the test work in all language modes.
1+
// RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- -fno-delayed-template-parsing
72

83
const unsigned int g_null = 0;
94
#define NULL 0
@@ -23,26 +18,19 @@ void test_assignment() {
2318
p2 = p1;
2419
// CHECK-FIXES: p2 = p1;
2520

26-
const int null = 0;
27-
int *p3 = null;
28-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
29-
// CHECK-FIXES: int *p3 = nullptr;
30-
21+
int *p3;
3122
p3 = NULL;
3223
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
3324
// CHECK-FIXES: p3 = nullptr;
3425

3526
int *p4 = p3;
3627
// CHECK-FIXES: int *p4 = p3;
3728

38-
p4 = null;
39-
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use nullptr
40-
// CHECK-FIXES: p4 = nullptr;
41-
4229
int i1 = 0;
4330

4431
int i2 = NULL;
4532

33+
const int null = 0;
4634
int i3 = null;
4735

4836
int *p5, *p6, *p7;
@@ -70,47 +58,13 @@ int *Foo::m_p2 = NULL;
7058
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: use nullptr
7159
// CHECK-FIXES: int *Foo::m_p2 = nullptr;
7260

73-
template <typename T>
74-
struct Bar {
75-
Bar(T *p) : m_p(p) {
76-
m_p = static_cast<T*>(NULL);
77-
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
78-
// CHECK-FIXES: m_p = static_cast<T*>(nullptr);
79-
80-
m_p = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
81-
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
82-
// CHECK-FIXES: m_p = static_cast<T*>(nullptr);
83-
84-
m_p = static_cast<T*>(p ? p : static_cast<void*>(g_null));
85-
// CHECK-MESSAGES: :[[@LINE-1]]:54: warning: use nullptr
86-
// CHECK-FIXES: m_p = static_cast<T*>(p ? p : static_cast<void*>(nullptr));
87-
88-
T *p2 = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
89-
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use nullptr
90-
// CHECK-FIXES: T *p2 = static_cast<T*>(nullptr);
91-
92-
m_p = NULL;
93-
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use nullptr
94-
// CHECK-FIXES: m_p = nullptr;
95-
96-
int i = static_cast<int>(0.f);
97-
T *i2 = static_cast<int>(0.f);
98-
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
99-
// CHECK-FIXES: T *i2 = nullptr;
100-
}
101-
102-
T *m_p;
103-
};
104-
10561
struct Baz {
10662
Baz() : i(0) {}
10763
int i;
10864
};
10965

11066
void test_cxx_cases() {
111-
Foo f(g_null);
112-
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
113-
// CHECK-FIXES: Foo f(nullptr);
67+
Foo f;
11468

11569
f.bar(NULL);
11670
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
@@ -122,10 +76,6 @@ void test_cxx_cases() {
12276
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr
12377
// CHECK-FIXES: f.m_p1 = nullptr;
12478

125-
Bar<int> b(g_null);
126-
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use nullptr
127-
// CHECK-FIXES: Bar<int> b(nullptr);
128-
12979
Baz b2;
13080
int Baz::*memptr(0);
13181
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: use nullptr
@@ -144,10 +94,6 @@ void test_function_default_param2(void *p = NULL);
14494
// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: use nullptr
14595
// CHECK-FIXES: void test_function_default_param2(void *p = nullptr);
14696

147-
void test_function_default_param3(void *p = g_null);
148-
// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: use nullptr
149-
// CHECK-FIXES: void test_function_default_param3(void *p = nullptr);
150-
15197
void test_function(int *p) {}
15298

15399
void test_function_no_ptr_param(int i) {}
@@ -161,10 +107,6 @@ void test_function_call() {
161107
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
162108
// CHECK-FIXES: test_function(nullptr);
163109

164-
test_function(g_null);
165-
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: use nullptr
166-
// CHECK-FIXES: test_function(nullptr);
167-
168110
test_function_no_ptr_param(0);
169111
}
170112

@@ -180,51 +122,33 @@ void *test_function_return2() {
180122
// CHECK-FIXES: return nullptr;
181123
}
182124

183-
long *test_function_return3() {
184-
return g_null;
185-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
186-
// CHECK-FIXES: return nullptr;
187-
}
188-
189-
int test_function_return4() {
125+
int test_function_return3() {
190126
return 0;
191127
}
192128

193-
int test_function_return5() {
129+
int test_function_return4() {
194130
return NULL;
195131
}
196132

197-
int test_function_return6() {
133+
int test_function_return5() {
198134
return g_null;
199135
}
200136

201-
int *test_function_return_cast1() {
202-
return(int)0;
203-
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use nullptr
204-
// CHECK-FIXES: return nullptr;
205-
}
206-
207-
int *test_function_return_cast2() {
137+
int *test_function_return_cast() {
208138
#define RET return
209-
RET(int)0;
210-
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use nullptr
139+
RET 0;
140+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr
211141
// CHECK-FIXES: RET nullptr;
212142
#undef RET
213143
}
214144

215145
// Test parentheses expressions resulting in a nullptr.
216-
int *test_parentheses_expression1() {
146+
int *test_parentheses_expression() {
217147
return(0);
218148
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
219149
// CHECK-FIXES: return(nullptr);
220150
}
221151

222-
int *test_parentheses_expression2() {
223-
return(int(0.f));
224-
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use nullptr
225-
// CHECK-FIXES: return(nullptr);
226-
}
227-
228152
int *test_nested_parentheses_expression() {
229153
return((((0))));
230154
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use nullptr
@@ -244,7 +168,7 @@ void *test_parentheses_explicit_cast_sequence1() {
244168
}
245169

246170
void *test_parentheses_explicit_cast_sequence2() {
247-
return(static_cast<void*>(reinterpret_cast<int*>((float*)int(0.f))));
171+
return(static_cast<void*>(reinterpret_cast<int*>((float*)(0))));
248172
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use nullptr
249173
// CHECK-FIXES: return(static_cast<void*>(nullptr));
250174
}
@@ -313,19 +237,13 @@ void test_const_pointers() {
313237
const int *const_p2 = NULL;
314238
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
315239
// CHECK-FIXES: const int *const_p2 = nullptr;
316-
const int *const_p3 = (int)0;
317-
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
318-
// CHECK-FIXES: const int *const_p3 = nullptr;
319-
const int *const_p4 = (int)0.0f;
320-
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use nullptr
321-
// CHECK-FIXES: const int *const_p4 = nullptr;
322-
const int *const_p5 = (int*)0;
240+
const int *const_p3 = (int*)0;
323241
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: use nullptr
324-
// CHECK-FIXES: const int *const_p5 = (int*)nullptr;
242+
// CHECK-FIXES: const int *const_p3 = (int*)nullptr;
325243
int *t;
326-
const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(0));
244+
const int *const_p4 = static_cast<int*>(t ? t : static_cast<int*>(0));
327245
// CHECK-MESSAGES: :[[@LINE-1]]:69: warning: use nullptr
328-
// CHECK-FIXES: const int *const_p6 = static_cast<int*>(t ? t : static_cast<int*>(nullptr));
246+
// CHECK-FIXES: const int *const_p4 = static_cast<int*>(t ? t : static_cast<int*>(nullptr));
329247
}
330248

331249
void test_nested_implicit_cast_expr() {
@@ -348,7 +266,21 @@ void test_nested_implicit_cast_expr() {
348266
template<typename T>
349267
class A {
350268
public:
351-
A(T *p = NULL) {}
269+
A(T *p = NULL) {
270+
Ptr = static_cast<T*>(NULL);
271+
272+
Ptr = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
273+
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: use nullptr
274+
// CHECK-FIXES: Ptr = static_cast<T*>(nullptr);
275+
// FIXME: a better fix-it is: Ptr = nullptr;
276+
277+
T *p2 = static_cast<T*>(reinterpret_cast<int*>((void*)NULL));
278+
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use nullptr
279+
// CHECK-FIXES: T *p2 = static_cast<T*>(nullptr);
280+
// FIXME: a better fix-it is: T *p2 = nullptr;
281+
282+
Ptr = NULL;
283+
}
352284

353285
void f() {
354286
Ptr = NULL;

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ C++ Specific Potentially Breaking Changes
8484
static_assert((b.*mp)() == 1); // newly rejected
8585
static_assert((c.*mp)() == 1); // accepted
8686
87+
- ``VarTemplateSpecializationDecl::getTemplateArgsAsWritten()`` method now
88+
returns ``nullptr`` for implicitly instantiated declarations.
89+
8790
ABI Changes in This Version
8891
---------------------------
8992

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11668,7 +11668,8 @@ class Sema final : public SemaBase {
1166811668
DeclResult CheckVarTemplateId(VarTemplateDecl *Template,
1166911669
SourceLocation TemplateLoc,
1167011670
SourceLocation TemplateNameLoc,
11671-
const TemplateArgumentListInfo &TemplateArgs);
11671+
const TemplateArgumentListInfo &TemplateArgs,
11672+
bool SetWrittenArgs);
1167211673

1167311674
/// Form a reference to the specialization of the given variable template
1167411675
/// corresponding to the specified argument list, or a null-but-valid result
@@ -14028,7 +14029,6 @@ class Sema final : public SemaBase {
1402814029
VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
1402914030
VarTemplateDecl *VarTemplate, VarDecl *FromVar,
1403014031
const TemplateArgumentList *PartialSpecArgs,
14031-
const TemplateArgumentListInfo &TemplateArgsInfo,
1403214032
SmallVectorImpl<TemplateArgument> &Converted,
1403314033
SourceLocation PointOfInstantiation,
1403414034
LateInstantiatedAttrVec *LateAttrs = nullptr,

clang/include/clang/Sema/Template.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,8 @@ enum class TemplateSubstitutionKind : char {
723723
bool SubstQualifier(const TagDecl *OldDecl,
724724
TagDecl *NewDecl);
725725

726-
Decl *VisitVarTemplateSpecializationDecl(
726+
VarTemplateSpecializationDecl *VisitVarTemplateSpecializationDecl(
727727
VarTemplateDecl *VarTemplate, VarDecl *FromVar,
728-
const TemplateArgumentListInfo &TemplateArgsInfo,
729728
ArrayRef<TemplateArgument> Converted,
730729
VarTemplateSpecializationDecl *PrevDecl = nullptr);
731730

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,9 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
11261126
return ExprError();
11271127
}
11281128

1129-
DeclResult VDecl = CheckVarTemplateId(VarTempl, TemplateKWLoc,
1130-
MemberNameInfo.getLoc(), *TemplateArgs);
1129+
DeclResult VDecl =
1130+
CheckVarTemplateId(VarTempl, TemplateKWLoc, MemberNameInfo.getLoc(),
1131+
*TemplateArgs, /*SetWrittenArgs=*/false);
11311132
if (VDecl.isInvalid())
11321133
return ExprError();
11331134

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4542,7 +4542,8 @@ static bool IsLibstdcxxStdFormatKind(Preprocessor &PP, VarDecl *Var) {
45424542
DeclResult
45434543
Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
45444544
SourceLocation TemplateNameLoc,
4545-
const TemplateArgumentListInfo &TemplateArgs) {
4545+
const TemplateArgumentListInfo &TemplateArgs,
4546+
bool SetWrittenArgs) {
45464547
assert(Template && "A variable template id without template?");
45474548

45484549
// Check that the template argument list is well-formed for this template.
@@ -4725,10 +4726,12 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, SourceLocation TemplateLoc,
47254726
// in DoMarkVarDeclReferenced().
47264727
// FIXME: LateAttrs et al.?
47274728
VarTemplateSpecializationDecl *Decl = BuildVarTemplateInstantiation(
4728-
Template, InstantiationPattern, PartialSpecArgs, TemplateArgs,
4729-
CTAI.CanonicalConverted, TemplateNameLoc /*, LateAttrs, StartingScope*/);
4729+
Template, InstantiationPattern, PartialSpecArgs, CTAI.CanonicalConverted,
4730+
TemplateNameLoc /*, LateAttrs, StartingScope*/);
47304731
if (!Decl)
47314732
return true;
4733+
if (SetWrittenArgs)
4734+
Decl->setTemplateArgsAsWritten(TemplateArgs);
47324735

47334736
if (AmbiguousPartialSpec) {
47344737
// Partial ordering did not produce a clear winner. Complain.
@@ -4760,7 +4763,7 @@ ExprResult Sema::CheckVarTemplateId(
47604763
const TemplateArgumentListInfo *TemplateArgs) {
47614764

47624765
DeclResult Decl = CheckVarTemplateId(Template, TemplateLoc, NameInfo.getLoc(),
4763-
*TemplateArgs);
4766+
*TemplateArgs, /*SetWrittenArgs=*/false);
47644767
if (Decl.isInvalid())
47654768
return ExprError();
47664769

@@ -10707,8 +10710,9 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
1070710710
TemplateArgumentListInfo TemplateArgs =
1070810711
makeTemplateArgumentListInfo(*this, *D.getName().TemplateId);
1070910712

10710-
DeclResult Res = CheckVarTemplateId(PrevTemplate, TemplateLoc,
10711-
D.getIdentifierLoc(), TemplateArgs);
10713+
DeclResult Res =
10714+
CheckVarTemplateId(PrevTemplate, TemplateLoc, D.getIdentifierLoc(),
10715+
TemplateArgs, /*SetWrittenArgs=*/true);
1071210716
if (Res.isInvalid())
1071310717
return true;
1071410718

0 commit comments

Comments
 (0)