Skip to content

Commit a383b3c

Browse files
authored
[clang] CTAD alias: Emit a more descriptive diagnostic message when is_deducible constraint is evaluated to false. (#92389)
Fixes #92225
1 parent 9a7f54b commit a383b3c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,8 @@ def note_single_arg_concept_specialization_constraint_evaluated_to_false : Note<
30033003
"%select{and|because}0 %1 does not satisfy %2">;
30043004
def note_atomic_constraint_evaluated_to_false_elaborated : Note<
30053005
"%select{and|because}0 '%1' (%2 %3 %4) evaluated to false">;
3006+
def note_is_deducible_constraint_evaluated_to_false : Note<
3007+
"cannot deduce template arguments for %0 from %1">;
30063008
def err_constrained_virtual_method : Error<
30073009
"virtual function cannot have a requires clause">;
30083010
def err_trailing_requires_clause_on_deduction_guide : Error<

clang/lib/Sema/SemaConcept.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,13 @@ static void diagnoseWellFormedUnsatisfiedConstraintExpr(Sema &S,
11621162
break;
11631163
}
11641164
return;
1165+
} else if (auto *TTE = dyn_cast<TypeTraitExpr>(SubstExpr);
1166+
TTE && TTE->getTrait() == clang::TypeTrait::BTT_IsDeducible) {
1167+
assert(TTE->getNumArgs() == 2);
1168+
S.Diag(SubstExpr->getSourceRange().getBegin(),
1169+
diag::note_is_deducible_constraint_evaluated_to_false)
1170+
<< TTE->getArg(0)->getType() << TTE->getArg(1)->getType();
1171+
return;
11651172
}
11661173

11671174
S.Diag(SubstExpr->getSourceRange().getBegin(),

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct Foo {
111111
template <typename X, int Y>
112112
using Bar = Foo<X, sizeof(X)>; // expected-note {{candidate template ignored: couldn't infer template argument 'X'}} \
113113
// expected-note {{candidate template ignored: constraints not satisfied [with X = int]}} \
114-
// expected-note {{because '__is_deducible}}
114+
// expected-note {{cannot deduce template arguments for 'Bar' from 'Foo<int, 4UL>'}}
115115

116116

117117
Bar s = {{1}}; // expected-error {{no viable constructor or deduction guide }}
@@ -138,7 +138,7 @@ template<class T> struct Foo { T c; };
138138
template<class X, class Y=A>
139139
using AFoo = Foo<Y>; // expected-note {{candidate template ignored: could not match 'Foo<type-parameter-0-0>' against 'int'}} \
140140
// expected-note {{candidate template ignored: constraints not satisfied [with Y = int]}} \
141-
// expected-note {{because '__is_deducible(AFoo, Foo<int>)' evaluated to false}} \
141+
// expected-note {{cannot deduce template arguments for 'AFoo' from 'Foo<int>'}} \
142142
// expected-note {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
143143

144144
AFoo s = {1}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'AFoo'}}
@@ -196,10 +196,9 @@ template <class T> struct Foo { Foo(T); };
196196

197197
template<class V> using AFoo = Foo<V *>;
198198
template<typename> concept False = false;
199-
// FIXME: emit a more descriptive diagnostic for "__is_deducible" constraint failure.
200199
template<False W>
201200
using BFoo = AFoo<W>; // expected-note {{candidate template ignored: constraints not satisfied [with V = int]}} \
202-
// expected-note {{because '__is_deducible(BFoo, Foo<int *>)' evaluated to false}} \
201+
// expected-note {{cannot deduce template arguments for 'BFoo' from 'Foo<int *>'}} \
203202
// expected-note {{candidate template ignored: could not match 'Foo<type-parameter-0-0 *>' against 'int *'}}
204203
int i = 0;
205204
AFoo a1(&i); // OK, deduce Foo<int *>

0 commit comments

Comments
 (0)