Skip to content

Commit d3d9ff3

Browse files
committed
cleanup fold expression tests
1 parent 4fe9a16 commit d3d9ff3

File tree

3 files changed

+39
-56
lines changed

3 files changed

+39
-56
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@ SubstitutionInTemplateArguments(
367367

368368
Sema::SFINAETrap Trap(S);
369369

370-
// TODO substitute at the appropriate depth
371-
// Template->getTemplateDepth();
372-
373370
TemplateArgumentListInfo SubstArgs;
374371
if (Constraint.hasParameterMapping()) {
375372
Sema::ArgPackSubstIndexRAII SubstIndex(
@@ -396,10 +393,6 @@ SubstitutionInTemplateArguments(
396393
for (unsigned I = 0, MappedIndex = 0; I < Used.size(); I++) {
397394
TemplateArgument Arg;
398395
if (Used[I])
399-
// SubstitutedOuterMost[I].dump();
400-
// SubstArgs[MappedIndex].getArgument().dump();
401-
// Arg = S.Context.getCanonicalTemplateArgument(
402-
// SubstArgs[MappedIndex++].getArgument());
403396
Arg = S.Context.getCanonicalTemplateArgument(
404397
CTAI.SugaredConverted[MappedIndex++]);
405398
if (I < SubstitutedOuterMost.size())
@@ -671,21 +664,20 @@ static bool calculateConstraintSatisfaction(
671664

672665
auto EffectiveDetailEndIndex = Satisfaction.Details.size();
673666

667+
bool Conjunction = Constraint.getCompoundKind() == NormalizedConstraint::CCK_Conjunction;
668+
674669
bool Ok = calculateConstraintSatisfaction(
675670
S, Constraint.getLHS(), Template, TemplateNameLoc, MLTAL, Satisfaction,
676671
PackSubstitutionIndex);
677672

678-
if (!Ok || Satisfaction.ContainsErrors)
679-
return Ok;
673+
if(Conjunction && !Ok)
674+
return false;
680675

681-
if (Satisfaction.IsSatisfied &&
682-
Constraint.getCompoundKind() == NormalizedConstraint::CCK_Disjunction) {
676+
if (!Conjunction && Ok && Satisfaction.IsSatisfied && !Satisfaction.ContainsErrors)
683677
return true;
684-
}
685-
if (!Satisfaction.IsSatisfied &&
686-
Constraint.getCompoundKind() == NormalizedConstraint::CCK_Conjunction) {
678+
679+
if (Conjunction && Ok && (!Satisfaction.IsSatisfied || Satisfaction.ContainsErrors))
687680
return true;
688-
}
689681

690682
Satisfaction.ContainsErrors = false;
691683
Satisfaction.IsSatisfied = false;

clang/test/SemaCXX/cxx2c-fold-exprs.cpp

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,23 @@ constexpr int i(T...) { return 1; }; // expected-note {{candidate}}
4040
static_assert(i(0) == 1); // expected-error {{call to 'i' is ambiguous}}
4141

4242

43-
template <class... T> requires (A<T> || ... || true)
44-
constexpr int j(T...) { return 0; };
45-
template <class... T> requires (C<T> && ... && true)
46-
constexpr int j(T...) { return 1; };
43+
template <class... T> requires (A<T> || ... || true) constexpr int j(T...) { return 0; }; // #j1
44+
template <class... T> requires (C<T> && ... && true) constexpr int j(T...) { return 1; }; // #j2
4745

4846
static_assert(j(0) == 1);
47+
// expected-error@-1 {{call to 'j' is ambiguous}}
48+
// expected-note@#j1 {{candidate function [with T = <int>]}}
49+
// expected-note@#j2 {{candidate function [with T = <int>]}}
50+
// expected-note@#j2 {{imilar constraint expressions not considered equivalent}}
51+
// expected-note@#j1 {{similar constraint expression here}}
52+
53+
4954
static_assert(j() == 1);
55+
// expected-error@-1 {{call to 'j' is ambiguous}}
56+
// expected-note@#j1 {{candidate function [with T = <>]}}
57+
// expected-note@#j2 {{candidate function [with T = <>]}}
58+
// expected-note@#j2 {{imilar constraint expressions not considered equivalent}}
59+
// expected-note@#j1 {{similar constraint expression here}}
5060

5161

5262

@@ -145,51 +155,41 @@ static_assert(And1<>() == 1);
145155
static_assert(And1<S>() == 1);
146156
static_assert(And1<S, S>() == 1);
147157
static_assert(And1<int>() == 1); // expected-error {{no matching function for call to 'And1'}}
148-
// expected-note@#and1 {{candidate template ignored: constraints not satisfied}}
149-
// expected-note@#and1 {{because substituted constraint expression is ill-formed}}
158+
// expected-note@#and1 {{candidate template ignored: failed template argument deduction}}
150159

151160
static_assert(And1<S, int>() == 1); // expected-error {{no matching function for call to 'And1'}}
152-
// expected-note@#and1 {{candidate template ignored: constraints not satisfied}}
153-
// expected-note@#and1 {{because substituted constraint expression is ill-formed}}
161+
// expected-note@#and1 {{candidate template ignored: failed template argument deduction}}
154162

155163
static_assert(And1<int, S>() == 1); // expected-error {{no matching function for call to 'And1'}}
156-
// expected-note@#and1 {{candidate template ignored: constraints not satisfied}}
157-
// expected-note@#and1 {{because substituted constraint expression is ill-formed}}
164+
// expected-note@#and1 {{candidate template ignored: failed template argument deduction}}
158165

159166
static_assert(And2<S>() == 2);
160167
static_assert(And2<S, S>() == 2);
161-
// FIXME: Should it compile??
162-
static_assert(And2<int>() == 2);
168+
static_assert(And2<int>() == 2); // expected-error {{no matching function for call to 'And2'}} \
169+
// expected-note@#and2 {{candidate template ignored: failed template argument deduction}}
163170

164171
static_assert(And2<int, int>() == 2); // expected-error {{no matching function for call to 'And2'}}
165-
// expected-note@#and2 {{candidate template ignored: constraints not satisfied}}
166-
// expected-note@#and2 {{because substituted constraint expression is ill-formed}}
172+
// expected-note@#and2 {{candidate template ignored: failed template argument deduction}}
167173

168174
static_assert(And2<S, int>() == 2); // expected-error {{no matching function for call to 'And2'}}
169-
// expected-note@#and2 {{candidate template ignored: constraints not satisfied}}
170-
// expected-note@#and2 {{because substituted constraint expression is ill-formed}}
175+
// expected-note@#and2 {{candidate template ignored: failed template argument deduction}}
171176

172177
static_assert(And2<int, S>() == 2); // expected-error {{no matching function for call to 'And2'}}
173-
// expected-note@#and2 {{candidate template ignored: constraints not satisfied}}
174-
// expected-note@#and2 {{because substituted constraint expression is ill-formed}}
178+
// expected-note@#and2 {{candidate template ignored: failed template argument deduction}}
175179

176180
static_assert(And3<S>() == 3);
177181
static_assert(And3<S, S>() == 3);
178182
static_assert(And3<int>() == 3); // expected-error {{no matching function for call to 'And3'}}
179-
// expected-note@#and3 {{candidate template ignored: constraints not satisfied}}
180-
// expected-note@#and3 {{because substituted constraint expression is ill-formed}}
183+
// expected-note@#and3 {{candidate template ignored: failed template argument deduction}}
181184

182185
static_assert(And3<int, int>() == 3); // expected-error {{no matching function for call to 'And3'}}
183-
// expected-note@#and3 {{candidate template ignored: constraints not satisfied}}
184-
// expected-note@#and3 {{because substituted constraint expression is ill-formed}}
186+
// expected-note@#and3 {{candidate template ignored: failed template argument deduction}}
185187

186188
static_assert(And3<S, int>() == 3); // expected-error {{no matching function for call to 'And3'}}
187-
// expected-note@#and3 {{candidate template ignored: constraints not satisfied}}
188-
// expected-note@#and3 {{because substituted constraint expression is ill-formed}}
189+
// expected-note@#and3 {{candidate template ignored: failed template argument deduction}}
189190

190191
static_assert(And3<int, S>() == 3); // expected-error {{no matching function for call to 'And3'}}
191-
// expected-note@#and3 {{candidate template ignored: constraints not satisfied}}
192-
// expected-note@#and3 {{because substituted constraint expression is ill-formed}}
192+
// expected-note@#and3 {{candidate template ignored: failed template argument deduction}}
193193

194194

195195
static_assert(Or1<>() == 1); // expected-error {{no matching function for call to 'Or1'}}
@@ -199,25 +199,20 @@ static_assert(Or1<int, S>() == 1);
199199
static_assert(Or1<S, int>() == 1);
200200
static_assert(Or1<S, S>() == 1);
201201
static_assert(Or1<int>() == 1); // expected-error {{no matching function for call to 'Or1'}}
202-
// expected-note@#or1 {{candidate template ignored: constraints not satisfied}} \
203-
// expected-note@#or1 {{because substituted constraint expression is ill-formed}}
204-
202+
// expected-note@#or1 {{candidate template ignored: constraints not satisfied}}
205203

206204
static_assert(Or2<S>() == 2);
207205
static_assert(Or2<int, S>() == 2);
208206
static_assert(Or2<S, int>() == 2);
209207
static_assert(Or2<S, S>() == 2);
210208
static_assert(Or2<int>() == 2); // expected-error {{no matching function for call to 'Or2'}}
211-
// expected-note@#or2 {{candidate template ignored: constraints not satisfied}} \
212-
// expected-note@#or2 {{because substituted constraint expression is ill-formed}}
213-
209+
// expected-note@#or2 {{candidate template ignored: failed template argument deduction}}
214210
static_assert(Or3<S>() == 3);
215211
static_assert(Or3<int, S>() == 3);
216212
static_assert(Or3<S, int>() == 3);
217213
static_assert(Or3<S, S>() == 3);
218214
static_assert(Or3<int>() == 3); // expected-error {{no matching function for call to 'Or3'}}
219-
// expected-note@#or3 {{candidate template ignored: constraints not satisfied}} \
220-
// expected-note@#or3 {{because substituted constraint expression is ill-formed}}
215+
// expected-note@#or3 {{candidate template ignored: constraints not satisfied}}
221216
}
222217

223218
namespace bool_conversion_break {
@@ -270,9 +265,7 @@ struct S {
270265

271266
static_assert(S<int>::f<int>() == 2);
272267

273-
static_assert(S<int>::g<int>() == 2); // expected-error {{call to 'g' is ambiguous}}
274-
// expected-note@#nested-ambiguous-g1 {{candidate}}
275-
// expected-note@#nested-ambiguous-g2 {{candidate}}
268+
static_assert(S<int>::g<int>() == 2);
276269

277270

278271
}

clang/test/SemaTemplate/concepts.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ template<class>
10001000
concept True = true;
10011001

10021002
template<class>
1003-
concept False = false; // expected-note 8 {{'false' evaluated to false}}
1003+
concept False = false; // expected-note 9 {{'false' evaluated to false}}
10041004

10051005
template<class>
10061006
concept Irrelevant = false;
@@ -1027,9 +1027,7 @@ template<class T> void eee(T t) // expected-note {{candidate template ignored: c
10271027
requires (Irrelevant<T> || Irrelevant<T> || True<T>) && False<T> {} // expected-note {{'long' does not satisfy 'False'}}
10281028

10291029
template<class T> void fff(T t) // expected-note {{candidate template ignored: constraints not satisfied}}
1030-
requires((ErrorRequires<T> || False<T> || True<T>) && False<T>) {} // expected-note {{because 'unsigned long' does not satisfy 'ErrorRequires'}}
1031-
// // expected-note@#GH54678-ill-formed-concept {{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
1032-
1030+
requires((ErrorRequires<T> || False<T> || True<T>) && False<T>) {} // expected-note {{because 'unsigned long' does not satisfy 'False'}}
10331031
void test() {
10341032
aaa(42); // expected-error {{no matching function}}
10351033
bbb(42L); // expected-error{{no matching function}}

0 commit comments

Comments
 (0)