public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67084] New: [c++-concepts] Matching of variable template declarations ignores constraints
@ 2015-07-31 16:51 Casey at Carter dot net
  2015-08-04  5:09 ` [Bug c++/67084] " jason at gcc dot gnu.org
  2015-08-04  5:09 ` jason at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: Casey at Carter dot net @ 2015-07-31 16:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67084

            Bug ID: 67084
           Summary: [c++-concepts] Matching of variable template
                    declarations ignores constraints
           Product: gcc
           Version: c++-concepts
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Casey at Carter dot net
  Target Milestone: ---

Created attachment 36102
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36102&action=edit
Test case

The two declarations of p<T> should be distinct due to having different
constraints:

template <class T>
constexpr bool p = true;

template <class T>
  requires true
constexpr bool p<T> = false;

template <class T>
  requires true && false
constexpr bool p<T> = true;

Compiling this program with r226419 results in:

~/concept-gcc/bin/g++ -std=gnu++1z foo.cpp -c
foo.cpp:10:16: error: redefinition of ‘const bool p<T>’
 constexpr bool p<T> = true;
                ^
foo.cpp:6:16: note: ‘constexpr const bool p<T>’ previously declared here
 constexpr bool p<T> = false;
                ^
foo.cpp:10:16: internal compiler error: in set_constraints, at cp/pt.c:23421
 constexpr bool p<T> = true;
                ^
0x63ae8d set_constraints(tree_node*, tree_node*)
        ../../gcc/cp/pt.c:23421
0x673e91 process_partial_specialization
        ../../gcc/cp/pt.c:4728
0x675467 push_template_decl_real(tree_node*, bool)
        ../../gcc/cp/pt.c:5250
0x6214c4 start_decl(cp_declarator const*, cp_decl_specifier_seq*, int,
tree_node*, tree_node*, tree_node**)
        ../../gcc/cp/decl.c:4919
0x710720 cp_parser_init_declarator
        ../../gcc/cp/parser.c:17728
0x7113c4 cp_parser_single_declaration
        ../../gcc/cp/parser.c:24892
0x71155b cp_parser_template_declaration_after_parameters
        ../../gcc/cp/parser.c:24509
0x712104 cp_parser_explicit_template_declaration
        ../../gcc/cp/parser.c:24744
0x712104 cp_parser_template_declaration_after_export
        ../../gcc/cp/parser.c:24762
0x718aa9 cp_parser_declaration
        ../../gcc/cp/parser.c:11416
0x7170fa cp_parser_declaration_seq_opt
        ../../gcc/cp/parser.c:11338
0x717411 cp_parser_translation_unit
        ../../gcc/cp/parser.c:4153
0x717411 c_parse_file()
        ../../gcc/cp/parser.c:34295
0x85ea22 c_common_parse_file()
        ../../gcc/c-family/c-opts.c:1059
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

An equivalent program with class templates or function templates overloaded
similarly does compile correctly.
>From gcc-bugs-return-493843-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Jul 31 18:00:47 2015
Return-Path: <gcc-bugs-return-493843-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 15713 invoked by alias); 31 Jul 2015 18:00:47 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 15634 invoked by uid 48); 31 Jul 2015 18:00:43 -0000
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/67070] [concepts] Concept with negation and disjunction not checked correctly
Date: Fri, 31 Jul 2015 18:00:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: c++-concepts
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jason at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on everconfirmed
Message-ID: <bug-67070-4-9DCX1wp0Wn@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67070-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67070-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-07/txt/msg02733.txt.bz2
Content-length: 2128

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg070

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-07-31
     Ever confirmed|0                           |1

--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> ---
This issue is another consequence of my earlier observation about the !
operator, that it produces a single predicate.

Reduced:

template <class T> concept bool A
  = requires { typename T::Type; } && T::Type::value;

template <class T> requires !A<T>
void f() { }

struct B { };

int main()
{
  f<B>();
}

Here f has a single atomic predicate constraint,

  !(requires { typename T::Type } && T::Type::value)

Substitution into this constraint fails because B has no member Type, and
template argument substitution doesn't stop after substituting into the
requires-expression.  Since argument substitution fails, the predicate
constraint is not satisfied.

We can make this work by moving the second reference to T::Type inside the
requires-expression:

template <class T> concept bool A
  = requires {
      typename T::Type;
      requires T::Type::value;
    };

template <class T> requires !A<T>
void f() { }

struct B { };

int main()
{
  f<B>();
}

Your testcase has this problem with Dereferenceable and Range, though fixing
that doesn't make it work; I expect there's something else similar going on.

This is a very subtle point.  It seems to me that it would be better if
creating the normal form of a constaint stops substituting into concept bodies
once it's clear that we're inside an atomic constraint.  So f would have a
single atomic predicate constraint

 !A<T>

and then when we consider this later we try to satisfy A<B>, which fails, so
f's constraint is satisfied and the testcase succeeds.  Though this does create
an inconsistency in argument substitution behavior across the ! operator, which
might be confusing.

Any thoughts, Andrew?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/67084] [c++-concepts] Matching of variable template declarations ignores constraints
  2015-07-31 16:51 [Bug c++/67084] New: [c++-concepts] Matching of variable template declarations ignores constraints Casey at Carter dot net
@ 2015-08-04  5:09 ` jason at gcc dot gnu.org
  2015-08-04  5:09 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jason at gcc dot gnu.org @ 2015-08-04  5:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67084

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org

--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed.

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Tue Aug  4 05:07:10 2015
New Revision: 226546

URL: https://gcc.gnu.org/viewcvs?rev=226546&root=gcc&view=rev
Log:
        PR c++/67084
        * pt.c (spec_hasher::equal): Compare constraints.
        (check_explicit_specialization): Don't register partial specs.
        (process_partial_specialization): Register them here.
        (lookup_template_class_1): Clear elt.spec.

Added:
    branches/c++-concepts/gcc/testsuite/g++.dg/concepts/partial-spec2.C
Modified:
    branches/c++-concepts/ChangeLog.concepts
    branches/c++-concepts/gcc/cp/pt.c


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/67084] [c++-concepts] Matching of variable template declarations ignores constraints
  2015-07-31 16:51 [Bug c++/67084] New: [c++-concepts] Matching of variable template declarations ignores constraints Casey at Carter dot net
  2015-08-04  5:09 ` [Bug c++/67084] " jason at gcc dot gnu.org
@ 2015-08-04  5:09 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jason at gcc dot gnu.org @ 2015-08-04  5:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67084

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org

--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed.

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Tue Aug  4 05:07:10 2015
New Revision: 226546

URL: https://gcc.gnu.org/viewcvs?rev=226546&root=gcc&view=rev
Log:
        PR c++/67084
        * pt.c (spec_hasher::equal): Compare constraints.
        (check_explicit_specialization): Don't register partial specs.
        (process_partial_specialization): Register them here.
        (lookup_template_class_1): Clear elt.spec.

Added:
    branches/c++-concepts/gcc/testsuite/g++.dg/concepts/partial-spec2.C
Modified:
    branches/c++-concepts/ChangeLog.concepts
    branches/c++-concepts/gcc/cp/pt.c


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-04  5:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-31 16:51 [Bug c++/67084] New: [c++-concepts] Matching of variable template declarations ignores constraints Casey at Carter dot net
2015-08-04  5:09 ` [Bug c++/67084] " jason at gcc dot gnu.org
2015-08-04  5:09 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).