This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[c++-concepts] function concepts with deduced return type
- From: Andrew Sutton <andrew dot n dot sutton at gmail dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 30 Sep 2014 08:54:03 -0400
- Subject: [c++-concepts] function concepts with deduced return type
- Authentication-results: sourceware.org; auth=none
Do not allow. Return type deduction only happens during instantiation,
and concepts are never instantiated. Therefore, we can't find the
return type of a function concept until you try to normalize the
return expression.
2014-09-25 Andrew Sutton <andrew.n.sutton@gmail.com>
Explicitly disallow function concepts with deduced return types.
* gcc/cp/constraint.cc (check_function_concept): Remove check
for deduced return type.
* gcc/cp/decl.c (check_concept_fn): Explicitly check for
deduced return type.
* gcc/testsuite/g++.dg/concepts/fn-concept2.C: New.
Andrew Sutton
Index: testsuite/g++.dg/concepts/fn-concept2.C
===================================================================
--- testsuite/g++.dg/concepts/fn-concept2.C (revision 0)
+++ testsuite/g++.dg/concepts/fn-concept2.C (revision 0)
@@ -0,0 +1,7 @@
+// { dg-options "-std=c++1z" }
+
+template<typename T>
+ concept auto C1() { return 0; } // { dg-error "deduced return type" }
+
+template<typename T>
+ concept int C2() { return 0; } // { dg-error "return type" }
Index: cp/constraint.cc
===================================================================
--- cp/constraint.cc (revision 215718)
+++ cp/constraint.cc (working copy)
@@ -280,11 +280,6 @@ check_function_concept (tree fn)
{
location_t loc = DECL_SOURCE_LOCATION (fn);
- // If fn was declared with auto, make sure the result type is bool.
- if (FNDECL_USED_AUTO (fn) && TREE_TYPE (fn) != boolean_type_node)
- error_at (loc, "deduced type of concept definition %qD is %qT and not %qT",
- fn, TREE_TYPE (fn), boolean_type_node);
-
// Check that the function is comprised of only a single
// return statement.
tree body = DECL_SAVED_TREE (fn);
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 215718)
+++ cp/decl.c (working copy)
@@ -7525,9 +7525,13 @@ check_concept_fn (tree fn)
if (DECL_ARGUMENTS (fn))
error ("concept %q#D declared with function parameters", fn);
- // The result type must be convertible to bool.
- if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
- error ("concept %q#D result must be bool", fn);
+ // The declared return type of the concept shall be bool, and
+ // it shall not be deduced from it definition.
+ tree type = TREE_TYPE (TREE_TYPE (fn));
+ if (is_auto (type))
+ error ("concept %q#D declared with a deduced return type", fn);
+ else if (type != boolean_type_node)
+ error ("concept %q#D with return type %qT", fn, type);
}
/* Helper function. Replace the temporary this parameter injected