Skip to content

Commit ca4c1ee

Browse files
committed
Merge remote-tracking branch 'upstream/release/13.x' into rustc/13.0-2021-08-08
2 parents 609f806 + aac4fe3 commit ca4c1ee

File tree

79 files changed

+3301
-751
lines changed

Some content is hidden

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

79 files changed

+3301
-751
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
7878
return;
7979

8080
QualType TypePtr = MatchedDecl->getType();
81-
const char *InitializationString = nullptr;
81+
llvm::Optional<const char *> InitializationString = llvm::None;
8282
bool AddMathInclude = false;
8383

84-
if (TypePtr->isIntegerType())
84+
if (TypePtr->isEnumeralType())
85+
InitializationString = nullptr;
86+
else if (TypePtr->isIntegerType())
8587
InitializationString = " = 0";
8688
else if (TypePtr->isFloatingType()) {
8789
InitializationString = " = NAN";
@@ -96,11 +98,12 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
9698
if (InitializationString) {
9799
auto Diagnostic =
98100
diag(MatchedDecl->getLocation(), "variable %0 is not initialized")
99-
<< MatchedDecl
100-
<< FixItHint::CreateInsertion(
101-
MatchedDecl->getLocation().getLocWithOffset(
102-
MatchedDecl->getName().size()),
103-
InitializationString);
101+
<< MatchedDecl;
102+
if (*InitializationString != nullptr)
103+
Diagnostic << FixItHint::CreateInsertion(
104+
MatchedDecl->getLocation().getLocWithOffset(
105+
MatchedDecl->getName().size()),
106+
*InitializationString);
104107
if (AddMathInclude) {
105108
Diagnostic << IncludeInserter.createIncludeInsertion(
106109
Source.getFileID(MatchedDecl->getBeginLoc()), MathHeader);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,22 @@ Changes in existing checks
151151

152152
Added an option to choose the set of allowed functions.
153153

154+
- Improved :doc:`cppcoreguidelines-init-variables
155+
<clang-tidy/checks/cppcoreguidelines-init-variables>` check.
156+
157+
Removed generating fixes for enums because the code generated was broken,
158+
trying to initialize the enum from an integer.
159+
160+
The check now also warns for uninitialized scoped enums.
161+
154162
- Improved :doc:`readability-uniqueptr-delete-release
155163
<clang-tidy/checks/readability-uniqueptr-delete-release>` check.
156164

157165
Added an option to choose whether to refactor by calling the ``reset`` member
158166
function or assignment to ``nullptr``.
159167
Added support for pointers to ``std::unique_ptr``.
160168

169+
161170
Removed checks
162171
^^^^^^^^^^^^^^
163172

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ Would be rewritten to look like this:
3737
// Rest of the function.
3838
}
3939

40+
It warns for the uninitialized enum case, but without a FixIt:
41+
42+
.. code-block:: c++
43+
44+
enum A {A1, A2, A3};
45+
enum A_c : char { A_c1, A_c2, A_c3 };
46+
enum class B { B1, B2, B3 };
47+
enum class B_i : int { B_i1, B_i2, B_i3 };
48+
void function() {
49+
A a; // Warning: variable 'a' is not initialized
50+
A_c a_c; // Warning: variable 'a_c' is not initialized
51+
B b; // Warning: variable 'b' is not initialized
52+
B_i b_i; // Warning: variable 'b_i' is not initialized
53+
}
54+
4055
Options
4156
-------
4257

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,35 @@ void catch_variable_decl() {
9292
} catch (int X) {
9393
}
9494
}
95+
96+
enum Color { Red,
97+
Green,
98+
Blue };
99+
100+
enum Car { Benz,
101+
BMW = 20,
102+
Audi = BMW + 2 };
103+
104+
enum Gender : char { Male,
105+
Female };
106+
107+
enum class Direction { Up,
108+
Down,
109+
Left,
110+
Right };
111+
112+
enum class Fruit : int { Apple,
113+
Orange };
114+
115+
void uninitialized_enum() {
116+
Color color;
117+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'color' is not initialized [cppcoreguidelines-init-variables]
118+
Car car;
119+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'car' is not initialized [cppcoreguidelines-init-variables]
120+
Gender gender;
121+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'gender' is not initialized [cppcoreguidelines-init-variables]
122+
Direction direction;
123+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'direction' is not initialized [cppcoreguidelines-init-variables]
124+
Fruit fruit;
125+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'fruit' is not initialized [cppcoreguidelines-init-variables]
126+
}

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7828,8 +7828,7 @@ class Sema final {
78287828
TemplateArgumentLoc &Arg,
78297829
SmallVectorImpl<TemplateArgument> &Converted);
78307830

7831-
bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
7832-
TypeSourceInfo *Arg);
7831+
bool CheckTemplateArgument(TypeSourceInfo *Arg);
78337832
ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
78347833
QualType InstantiatedParamType, Expr *Arg,
78357834
TemplateArgument &Converted,

clang/lib/AST/ASTContext.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6066,9 +6066,11 @@ ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const {
60666066
NNS->getAsNamespaceAlias()->getNamespace()
60676067
->getOriginalNamespace());
60686068

6069+
// The difference between TypeSpec and TypeSpecWithTemplate is that the
6070+
// latter will have the 'template' keyword when printed.
60696071
case NestedNameSpecifier::TypeSpec:
60706072
case NestedNameSpecifier::TypeSpecWithTemplate: {
6071-
QualType T = getCanonicalType(QualType(NNS->getAsType(), 0));
6073+
const Type *T = getCanonicalType(NNS->getAsType());
60726074

60736075
// If we have some kind of dependent-named type (e.g., "typename T::type"),
60746076
// break it apart into its prefix and identifier, then reconsititute those
@@ -6078,14 +6080,16 @@ ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const {
60786080
// typedef typename T::type T1;
60796081
// typedef typename T1::type T2;
60806082
if (const auto *DNT = T->getAs<DependentNameType>())
6081-
return NestedNameSpecifier::Create(*this, DNT->getQualifier(),
6082-
const_cast<IdentifierInfo *>(DNT->getIdentifier()));
6083-
6084-
// Otherwise, just canonicalize the type, and force it to be a TypeSpec.
6085-
// FIXME: Why are TypeSpec and TypeSpecWithTemplate distinct in the
6086-
// first place?
6083+
return NestedNameSpecifier::Create(
6084+
*this, DNT->getQualifier(),
6085+
const_cast<IdentifierInfo *>(DNT->getIdentifier()));
6086+
if (const auto *DTST = T->getAs<DependentTemplateSpecializationType>())
6087+
return NestedNameSpecifier::Create(*this, DTST->getQualifier(), true,
6088+
const_cast<Type *>(T));
6089+
6090+
// TODO: Set 'Template' parameter to true for other template types.
60876091
return NestedNameSpecifier::Create(*this, nullptr, false,
6088-
const_cast<Type *>(T.getTypePtr()));
6092+
const_cast<Type *>(T));
60896093
}
60906094

60916095
case NestedNameSpecifier::Global:

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
136136
llvm_unreachable("Unsupported target architecture.");
137137
}
138138

139-
if (Args.hasArg(options::OPT_mwindows)) {
139+
Arg *SubsysArg =
140+
Args.getLastArg(options::OPT_mwindows, options::OPT_mconsole);
141+
if (SubsysArg && SubsysArg->getOption().matches(options::OPT_mwindows)) {
140142
CmdArgs.push_back("--subsystem");
141143
CmdArgs.push_back("windows");
142-
} else if (Args.hasArg(options::OPT_mconsole)) {
144+
} else if (SubsysArg &&
145+
SubsysArg->getOption().matches(options::OPT_mconsole)) {
143146
CmdArgs.push_back("--subsystem");
144147
CmdArgs.push_back("console");
145148
}

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12472,6 +12472,8 @@ bool Sema::CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
1247212472
return false;
1247312473
}
1247412474

12475+
const NestedNameSpecifier *CNNS =
12476+
Context.getCanonicalNestedNameSpecifier(Qual);
1247512477
for (LookupResult::iterator I = Prev.begin(), E = Prev.end(); I != E; ++I) {
1247612478
NamedDecl *D = *I;
1247712479

@@ -12497,8 +12499,7 @@ bool Sema::CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
1249712499
// using decls differ if they name different scopes (but note that
1249812500
// template instantiation can cause this check to trigger when it
1249912501
// didn't before instantiation).
12500-
if (Context.getCanonicalNestedNameSpecifier(Qual) !=
12501-
Context.getCanonicalNestedNameSpecifier(DQual))
12502+
if (CNNS != Context.getCanonicalNestedNameSpecifier(DQual))
1250212503
continue;
1250312504

1250412505
Diag(NameLoc, diag::err_using_decl_redeclaration) << SS.getRange();

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ NamedDecl *Sema::ActOnTypeParameter(Scope *S, bool Typename,
10791079
return Param;
10801080

10811081
// Check the template argument itself.
1082-
if (CheckTemplateArgument(Param, DefaultTInfo)) {
1082+
if (CheckTemplateArgument(DefaultTInfo)) {
10831083
Param->setInvalidDecl();
10841084
return Param;
10851085
}
@@ -5042,7 +5042,7 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
50425042
}
50435043
}
50445044

5045-
if (CheckTemplateArgument(Param, TSI))
5045+
if (CheckTemplateArgument(TSI))
50465046
return true;
50475047

50485048
// Add the converted template type argument.
@@ -5661,7 +5661,7 @@ bool Sema::CheckTemplateArgumentList(
56615661
TemplateArgumentListInfo NewArgs = TemplateArgs;
56625662

56635663
// Make sure we get the template parameter list from the most
5664-
// recentdeclaration, since that is the only one that has is guaranteed to
5664+
// recent declaration, since that is the only one that is guaranteed to
56655665
// have all the default template argument information.
56665666
TemplateParameterList *Params =
56675667
cast<TemplateDecl>(Template->getMostRecentDecl())
@@ -6208,8 +6208,7 @@ bool UnnamedLocalNoLinkageFinder::VisitNestedNameSpecifier(
62086208
///
62096209
/// This routine implements the semantics of C++ [temp.arg.type]. It
62106210
/// returns true if an error occurred, and false otherwise.
6211-
bool Sema::CheckTemplateArgument(TemplateTypeParmDecl *Param,
6212-
TypeSourceInfo *ArgInfo) {
6211+
bool Sema::CheckTemplateArgument(TypeSourceInfo *ArgInfo) {
62136212
assert(ArgInfo && "invalid TypeSourceInfo");
62146213
QualType Arg = ArgInfo->getType();
62156214
SourceRange SR = ArgInfo->getTypeLoc().getSourceRange();

clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,23 @@ template <True T, Bar2 U>
8181
requires true struct S4; // expected-note {{template is declared here}}
8282
template <True T, True U>
8383
requires true struct S4<T, U>; // expected-error {{class template partial specialization is not more specialized than the primary template}}
84+
85+
struct X {
86+
template<int> struct Y {
87+
using type = int;
88+
};
89+
};
90+
91+
template<class T> concept C1 = sizeof(T) != 0;
92+
template<class T> concept C2 = C1<typename T::template Y<1>::type>;
93+
94+
template<class T> requires C1<T> void t1() = delete; // expected-note {{candidate function}}
95+
template<class T> requires C1<T> && C2<T> void t1() = delete; // expected-note {{candidate function}}
96+
template void t1<X>();
97+
void t1() { t1<X>(); } // expected-error {{call to deleted function 't1'}}
98+
99+
template<class T> requires C1<T> void t2() {}; // expected-note 2 {{candidate function}}
100+
template<class T> requires C2<T> void t2() {}; // expected-note 2 {{candidate function}}
101+
template void t2<X>(); // expected-error {{partial ordering for explicit instantiation of 't2' is ambiguous}}
102+
void t2() { t2<X>(); } // expected-error {{call to 't2' is ambiguous}}
84103
} // namespace PR47174

0 commit comments

Comments
 (0)