[c++-concepts] Terse notation

Andrew Sutton andrew.n.sutton@gmail.com
Wed Jun 11 17:24:00 GMT 2014


Sorry if you receive multiple versions of this. The original message
bounced (formatting).

Attached is a patch that greatly improves terse notation support for
generic functions and the use of concept names in
constrained-type-specifiers. There are actually 2 patches. The second
includes unit tests. Mostly, this is just cleaning up a previous
(hacky) commit. Most of the work is done in the parser, since terse
notation is largely syntactic.

Generic functions can be declared with auto and concept names in
namespace and class scope. Definitions can be matched to declarations,
and overloading is supported.

Various restrictions are put in place to prevent things like this:

  template<const C&> // C constrains a type argument!

That holds when C constrains a template template argument also.

The patch also includes the initial parsing and semantic hooks for
handling constrained-type-specifiers in compound requirements:

  {expr} -> const auto&; // unnamed result type must form a valid type
  {expr} -> C; // unnamed result type satisfies the concept C

Semantics will come later.

Changelog:

2014-06-11  Andrew Sutton  <andrew.n.sutton@gmail.com>
        * gcc/cp/cp-tree.h (build_constrained_parameter): Renamed fro
        describe_tempalte_parm.
        * gcc/cp/parser.c (cp_check_constrained_type_parm): New. Prevent
        declaration of cv-qualifed or non-id types.
        (cp_constrained_type_template_parm): Renamed, check for invalid
        specifiers.
        (cp_constrained_template_template_parm): Renamed, check for invalid
        specifiers.
        (cp_constrained_non_type_tmeplate_parm): Renamed.
        (cp_finish_constrained-parameter): Support checking of decarlarations.
        (cp_check_concept_name): Renamed. Add initial support for auto
        and constrained-type-specifiers in compound requirements.
        (cp_parser_nonclass_name): Only check for concept names if -fconcepts
        is on.
        (cp_manage_requirements): New RAII guard for managinging the
        current_template_reqs variable during declaration parsing.
        (cp_paresr_trailing_requirements): Refactored common parsing
        requirements from cp_parser_init_declarator and
        cp_parser_member_declarator. Take terse constraints from implicit
        parameter declarations.
        (cp_parser_init_declarator): Cleanup, refactor requirement logic.
        (cp_parser_type_id_1): Allow auto in compound requirements.
        (cp_parser_member_declaration): Cleanup, refactor requirement logic.
        (cp_parser_compound_requirement): Note parsing state for the
        trailing-type-id so we can get auto and constrained-type-specifiers.
        (cp_parser_function_definition_after_decl): Remove broken constraint
        association.
        * gcc/cp/parser.h (cp_parser): New member.
        * gcc/cp/constraint.cc (finish_validtype_expr): Initial (non-)handling
        of auto in type requirements.
        (finish_concept_name): Moved to cp_check_concept_name.
        * gcc/testuite/g++.dg/concepts/constrained-parm.C: New test.
        * gcc/testuite/g++.dg/concepts/generic-fn.C: New test.

Andrew Sutton
-------------- next part --------------
A non-text attachment was scrubbed...
Name: terse1-test.patch
Type: text/x-patch
Size: 3095 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140611/e0c75cb5/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: terse-1.patch
Type: text/x-patch
Size: 23357 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140611/e0c75cb5/attachment-0001.bin>


More information about the Gcc-patches mailing list