+2019-11-05 Jason Merrill <jason@redhat.com>
+
+ * decl2.c (mark_used): Diagnose use of a function with unsatisfied
+ constraints here.
+ * typeck.c (cp_build_function_call_vec): Not here.
+
2019-11-05 Nathan Sidwell <nathan@acm.org>
PR c++/92370
directly. */
maybe_instantiate_decl (decl);
+ if (flag_concepts && TREE_CODE (decl) == FUNCTION_DECL
+ && !constraints_satisfied_p (decl))
+ {
+ if (complain & tf_error)
+ {
+ auto_diagnostic_group d;
+ error ("use of function %qD with unsatisfied constraints",
+ decl);
+ location_t loc = DECL_SOURCE_LOCATION (decl);
+ inform (loc, "declared here");
+ diagnose_constraints (loc, decl, NULL_TREE);
+ }
+ return false;
+ }
+
if (processing_template_decl || in_template_function ())
return true;
if (TREE_CODE (function) == FUNCTION_DECL)
{
- /* If the function is a non-template member function
- or a non-template friend, then we need to check the
- constraints.
-
- Note that if overload resolution failed with a single
- candidate this function will be used to explicitly diagnose
- the failure for the single call expression. The check is
- technically redundant since we also would have failed in
- add_function_candidate. */
- if (flag_concepts
- && (complain & tf_error)
- && !constraints_satisfied_p (function))
- {
- auto_diagnostic_group d;
- error ("cannot call function %qD", function);
- location_t loc = DECL_SOURCE_LOCATION (function);
- diagnose_constraints (loc, function, NULL_TREE);
- return error_mark_node;
- }
-
if (!mark_used (function, complain))
return error_mark_node;
fndecl = function;
int main()
{
- foo(1, 2, 3); // { dg-error "cannot call" }
- bar(1, 2, 3); // { dg-error "cannot call" }
+ foo(1, 2, 3); // { dg-error "" }
+ bar(1, 2, 3); // { dg-error "" }
}
int main()
{
- f1(s); // { dg-error "cannot call|private" }
+ f1(s); // { dg-error "unsatisfied|private" }
f2(s); // { dg-error "" }
// When used in non-SFINAE contexts, make sure that we fail
// Non-dependent args are checked even in dependent scope.
template<typename T>
void h(T x) {
- f(0); // { dg-error "cannot call" }
+ f(0); // { dg-error "" }
}
int main() {
- f(0); // { dg-error "cannot call" }
+ f(0); // { dg-error "" }
}
S1<char> s1; // { dg-error "constraint|invalid" }
S2<int, char> s2; // { dg-error "constraint|invalid" }
- f('a'); // { dg-error "cannot" }
- g(0, 'a'); // { dg-error "cannot" }
+ f('a'); // { dg-error "unsatisfied" }
+ g(0, 'a'); // { dg-error "unsatisfied" }
}
template<typename T> void fn(T) { }
-auto p1 = &f<int>; // { dg-error "no matches" }
+auto p1 = &f<int>; // { dg-error "" }
void (*p2)(int) = &f<int>; // { dg-error "no matches" }
void (*p3)(int) = &f; // { dg-error "no matches" }
template<Class T> int f(T) { return 0; }
};
-auto p4 = &S::template f<int>; // { dg-error "no matches" }
+auto p4 = &S::template f<int>; // { dg-error "" }
int (S::*p6)(int) = &S::template f<int>; // { dg-error "no matches" }
int (S::*p7)(int) = &S::f; // { dg-error "no matches" }
template <C c>
constexpr bool f() { return true; }
-static_assert(f<double>(), ""); // { dg-error "cannot call|as type" }
-static_assert(f<int>(), ""); // { dg-error "cannot call|as type" }
+static_assert(f<double>(), ""); // { dg-error "unsatisfied|as type" }
+static_assert(f<int>(), ""); // { dg-error "unsatisfied|as type" }
void f()
{
- getTable(7, 'a'); // { dg-error "cannot call" }
+ getTable(7, 'a'); // { dg-error "" }
};
int main ()
{
- f1(0, 0); // { dg-error "cannot call" }
- f2(1); // { dg-error "cannot call" }
+ f1(0, 0); // { dg-error "" }
+ f2(1); // { dg-error "" }
return 0;
}
int main()
{
- foo(1, 2, 3); // { dg-error "cannot call" }
+ foo(1, 2, 3); // { dg-error "" }
}
void driver()
{
fn1(0); // OK
- fn2(0); // { dg-error "cannot call function" }
+ fn2(0); // { dg-error "" }
}
// Ordering
{
f1(x); // Unchecked dependent arg.
f1(empty{}); // Checked non-dependent arg, but OK
- f1(0); // { dg-error "cannot call function" }
+ f1(0); // { dg-error "" }
}
// fn3.c -- Ordering
template<typename T> requires Class<T> void err(T) { }
auto p1 = &ok<int>;
-auto p2 = &err<int>; // { dg-error "no matches" }
+auto p2 = &err<int>; // { dg-error "" }
void (*p3)(int) = &ok<int>;
void (*p4)(int) = &err<int>; // { dg-error "no matches" }
void (*p5)(int) = &ok;
};
auto p7 = &S2::ok<int>;
-auto p8 = &S2::err<int>; // { dg-error "no matches" }
+auto p8 = &S2::err<int>; // { dg-error "" }
int (S2::*p9)(int) = &S2::ok<int>;
int (S2::*p10)(int) = &S2::err<int>; // { dg-error "no matches" }
int (S2::*p11)(int) = &S2::ok;
int main()
{
f1(1, 2, 3);
- f1(1, 2, 3u); // { dg-error "cannot call" }
+ f1(1, 2, 3u); // { dg-error "" }
f2(1, 2, 3);
- f2(1, 2, 3u); // { dg-error "cannot call" }
+ f2(1, 2, 3u); // { dg-error "" }
f3(1, 2, 3);
- f3(1, 2, 3u); // { dg-error "cannot call" }
+ f3(1, 2, 3u); // { dg-error "" }
f3(1u, 2, 3);
S<void> s;
--- /dev/null
+// Testcase from [expr.prim.id]/5
+// { dg-do compile { target c++2a } }
+
+template<typename T> struct A {
+ static void f(int) requires false;
+};
+void g() {
+ A<int>::f(0); // { dg-error "" "cannot call f" }
+ void (*p1)(int) = A<int>::f; // { dg-error "" "cannot take the address of f" }
+ decltype(A<int>::f)* p2 = nullptr; // { dg-error "" "the type decltype(A<int>::f) is invalid" }
+}
int main() {
// f(0); // OK
- f(nt); // { dg-error "cannot call" }
+ f(nt); // { dg-error "" }
f(x); // { dg-error "3:'f' was not declared" }
S<int> si;
void g2(T t);
void test() {
- g1(0); // { dg-error "cannot call" }
+ g1(0); // { dg-error "" }
g2(0);
}
\ No newline at end of file
void driver_1()
{
- f19(0); // { dg-error "cannot call function" }
+ f19(0); // { dg-error "" }
f19(empty{});
- f20(0, empty{}); // { dg-error "cannot call function" }
+ f20(0, empty{}); // { dg-error "" }
f20(empty{}, empty{});
}
int
main()
{
- f1(); // { dg-error "cannot call" }
+ f1(); // { dg-error "" }
}
requires C<T1, T2>
int f();
-auto i = f<char, int>(); // { dg-error "cannot call function" }
+auto i = f<char, int>(); // { dg-error "" }
requires C<T>
constexpr bool is_c() { return true; }
-static_assert(is_c<void>(), ""); // { dg-error "cannot call" }
+static_assert(is_c<void>(), ""); // { dg-error "" }
};
void test2() {
- g1<X, X>(); // { dg-error "cannot call" }
- g2<X, X>(); // { dg-error "cannot call" }
+ g1<X, X>(); // { dg-error "" }
+ g2<X, X>(); // { dg-error "" }
}
\ No newline at end of file
void f(T) {}
int main() {
- f(1); // { dg-error "cannot call" }
+ f(1); // { dg-error "" }
}
int main()
{
- f<Y>(); // { dg-error "cannot call" }
+ f<Y>(); // { dg-error "" }
}
int main()
{
- foobar(S<double>{}, int{}); // { dg-error "cannot call" }
+ foobar(S<double>{}, int{}); // { dg-error "" }
}
struct S { } s;
f4(s);
f5(0);
- f5((void*)0); // { dg-error "cannot call" }
+ f5((void*)0); // { dg-error "" }
test.f(s);
}
void driver_3()
{
- print2("hello"); // { dg-error "cannot call" }
+ print2("hello"); // { dg-error "" }
}
void fun(T s) { }
int main(int, char **) {
- fun((int *)0); // { dg-error "cannot call function" }
+ fun((int *)0); // { dg-error "" }
return 0;
}
void driver()
{
- f1<int, int>(); // { dg-error "cannot call function" }
+ f1<int, int>(); // { dg-error "" }
f3<int, int>();
- f3<int, void>(); // { dg-error "cannot call function" }
+ f3<int, void>(); // { dg-error "" }
f4<int, int>();
- f4<int, void>(); // { dg-error "cannot call function" }
+ f4<int, void>(); // { dg-error "" }
f7<int>();
f7<int, int>();
}
void driver_2()
{
- bad(0); // { dg-error "cannot call" }
+ bad(0); // { dg-error "" }
}
// req6.C
void driver_3()
{
- h1(0); // { dg-error "cannot call" }
- h2(0); // { dg-error "cannot call" }
+ h1(0); // { dg-error "" }
+ h2(0); // { dg-error "" }
}
// req7.C
requires C1<T>
constexpr bool f1() { return true; }
-static_assert(f1<char>()); // { dg-error "cannot call" }
-static_assert(f1<int>()); // { dg-error "cannot call" }
-static_assert(f1<double>()); // { dg-error "cannot call" }
+static_assert(f1<char>()); // { dg-error "" }
+static_assert(f1<int>()); // { dg-error "" }
+static_assert(f1<double>()); // { dg-error "" }
template <typename T>
{
// FIXME: This diagnostic is being emitted twice, when it should
// be emitted just once.
- using U = decltype(f(42, non_addable{})); // { dg-error "cannot call function" }
+ using U = decltype(f(42, non_addable{})); // { dg-error "" }
}
template<Enum T> void f18() { }
int main() {
- f1<void>(); // { dg-error "cannot call" }
- f2<void>(); // { dg-error "cannot call" }
- f3<void>(); // { dg-error "cannot call" }
- f4<void>(); // { dg-error "cannot call" }
- f5<void>(); // { dg-error "cannot call" }
- f6<void>(); // { dg-error "cannot call" }
- f7<void>(); // { dg-error "cannot call" }
- f8<void>(); // { dg-error "cannot call" }
- f9<void>(); // { dg-error "cannot call" }
- f10<void>(); // { dg-error "cannot call" }
- f11<void>(); // { dg-error "cannot call" }
- f12<void>(); // { dg-error "cannot call" }
- f13<void>(); // { dg-error "cannot call" }
- f14<void>(); // { dg-error "cannot call" }
- f15<void>(); // { dg-error "cannot call" }
- f16<void>(); // { dg-error "cannot call" }
- f17<void>(); // { dg-error "cannot call" }
+ f1<void>(); // { dg-error "" }
+ f2<void>(); // { dg-error "" }
+ f3<void>(); // { dg-error "" }
+ f4<void>(); // { dg-error "" }
+ f5<void>(); // { dg-error "" }
+ f6<void>(); // { dg-error "" }
+ f7<void>(); // { dg-error "" }
+ f8<void>(); // { dg-error "" }
+ f9<void>(); // { dg-error "" }
+ f10<void>(); // { dg-error "" }
+ f11<void>(); // { dg-error "" }
+ f12<void>(); // { dg-error "" }
+ f13<void>(); // { dg-error "" }
+ f14<void>(); // { dg-error "" }
+ f15<void>(); // { dg-error "" }
+ f16<void>(); // { dg-error "" }
+ f17<void>(); // { dg-error "" }
}
int main() {
- f1<void>(); // { dg-error "cannot call" }
- f2<void>(); // { dg-error "cannot call" }
- f3<void>(); // { dg-error "cannot call" }
- f4<void>(); // { dg-error "cannot call" }
- f5<void>(); // { dg-error "cannot call" }
- f6<void>(); // { dg-error "cannot call" }
- f7<void>(); // { dg-error "cannot call" }
- f8<void>(); // { dg-error "cannot call" }
- f9<void>(); // { dg-error "cannot call" }
- f10<void>(); // { dg-error "cannot call" }
- f11<void>(); // { dg-error "cannot call" }
- f12<void>(); // { dg-error "cannot call" }
- f13<void>(); // { dg-error "cannot call" }
- f14<void>(); // { dg-error "cannot call" }
- f15<void>(); // { dg-error "cannot call" }
- f16<void>(); // { dg-error "cannot call" }
- f17<void>(); // { dg-error "cannot call" }
+ f1<void>(); // { dg-error "" }
+ f2<void>(); // { dg-error "" }
+ f3<void>(); // { dg-error "" }
+ f4<void>(); // { dg-error "" }
+ f5<void>(); // { dg-error "" }
+ f6<void>(); // { dg-error "" }
+ f7<void>(); // { dg-error "" }
+ f8<void>(); // { dg-error "" }
+ f9<void>(); // { dg-error "" }
+ f10<void>(); // { dg-error "" }
+ f11<void>(); // { dg-error "" }
+ f12<void>(); // { dg-error "" }
+ f13<void>(); // { dg-error "" }
+ f14<void>(); // { dg-error "" }
+ f15<void>(); // { dg-error "" }
+ f16<void>(); // { dg-error "" }
+ f17<void>(); // { dg-error "" }
}
void driver()
{
f1(0);
- f2(0); // { dg-error "cannot call" }
+ f2(0); // { dg-error "" }
f3(0);
- f3('a'); // { dg-error "cannot call" }
+ f3('a'); // { dg-error "" }
f4(0, 0);
- f4(0, 'a'); // { dg-error "cannot call" }
+ f4(0, 'a'); // { dg-error "" }
f15(0);
f15('a'); // { dg-message "" }
}
void driver()
{
fn1(0); // OK
- fn2(0); // { dg-error "cannot call function" }
+ fn2(0); // { dg-error "" }
}
// Ordering
{
f1(x); // Unchecked dependent arg.
f1(empty{}); // Checked non-dependent arg, but OK
- f1(0); // { dg-error "cannot call function" }
+ f1(0); // { dg-error "" }
}
// fn3.c -- Ordering
template<typename T> requires (Class<T>()) void err(T) { }
auto p1 = &ok<int>;
-auto p2 = &err<int>; // { dg-error "no matches" }
+auto p2 = &err<int>; // { dg-error "" }
void (*p3)(int) = &ok<int>;
void (*p4)(int) = &err<int>; // { dg-error "no matches" }
void (*p5)(int) = &ok;
};
auto p7 = &S2::ok<int>;
-auto p8 = &S2::err<int>; // { dg-error "no matches" }
+auto p8 = &S2::err<int>; // { dg-error "" }
int (S2::*p9)(int) = &S2::ok<int>;
int (S2::*p10)(int) = &S2::err<int>; // { dg-error "no matches" }
int (S2::*p11)(int) = &S2::ok;
void driver()
{
fn1(0); // OK
- fn2(0); // { dg-error "cannot call function" }
+ fn2(0); // { dg-error "" }
}
// Ordering
{
f1(x); // Unchecked dependent arg.
f1(empty{}); // Checked non-dependent arg, but OK
- f1(0); // { dg-error "cannot call function" }
+ f1(0); // { dg-error "" }
}
// fn3.c -- Ordering
template<typename T> requires Class<T> void err(T) { }
auto p1 = &ok<int>;
-auto p2 = &err<int>; // { dg-error "no matches" }
+auto p2 = &err<int>; // { dg-error "" }
void (*p3)(int) = &ok<int>;
void (*p4)(int) = &err<int>; // { dg-error "no matches" }
void (*p5)(int) = &ok;
};
auto p7 = &S2::ok<int>;
-auto p8 = &S2::err<int>; // { dg-error "no matches" }
+auto p8 = &S2::err<int>; // { dg-error "" }
int (S2::*p9)(int) = &S2::ok<int>;
int (S2::*p10)(int) = &S2::err<int>; // { dg-error "no matches" }
int (S2::*p11)(int) = &S2::ok;
void driver()
{
f1(0);
- f2(0); // { dg-error "cannot call function" }
+ f2(0); // { dg-error "" }
same<int, int>();
- same<int, char>(); // { dg-error "cannot call function" }
+ same<int, char>(); // { dg-error "" }
fn<0>(); // OK
- fn<-1>(); // { dg-error "cannot call function" }
+ fn<-1>(); // { dg-error "" }
fn<int>(); // { dg-error "no matching function" }
}
void driver_1()
{
- f1(0); // { dg-error "cannot call function" }
+ f1(0); // { dg-error "" }
f1(empty{});
decl1(empty{}); // { dg-error "call of overload | ambiguous" }
void f3() { }
void driver2() {
- f1<S1>(); // { dg-error "cannot call|is private" }
- f2<S1>(); // { dg-error "cannot call|is private" }
- f3<S1>(); // { dg-error "cannot call|is private" }
+ f1<S1>(); // { dg-error "unsatisfied|is private" }
+ f2<S1>(); // { dg-error "unsatisfied|is private" }
+ f3<S1>(); // { dg-error "unsatisfied|is private" }
}