Bug 96164 - Constraints and explicit template instantiation
Summary: Constraints and explicit template instantiation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.1.1
: P3 normal
Target Milestone: 10.3
Assignee: Patrick Palka
URL:
Keywords:
: 68608 77595 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-07-11 09:01 UTC by whoknows
Modified: 2023-03-15 13:25 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-07-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description whoknows 2020-07-11 09:01:53 UTC
The following code does not compile in all of gcc 10.1, msvc 19.24, and clang 10.0.0:

    template <int N>
    struct A {
        void g() requires (N == 3) {}
        void f() requires (N == 3) { g(); }
    };

    template struct A<2>;
Comment 1 whoknows 2020-07-11 09:04:26 UTC
The error is "use of function 'void A<N>::g() requires  N == 3 [with int N = 2]' with unsatisfied constraints"
Comment 2 Patrick Palka 2020-07-11 16:46:33 UTC
Confirmed.  [temp.explicit]/11 says:

An explicit instantiation that names a class template specialization is also an explicit instantiation of the same kind (declaration or definition) of each of its members (not including members inherited from base classes and members that are templates) that has not been previously explicitly specialized in the translation unit containing the explicit instantiation, ***provided that the associated constraints, if any, of that member are satisfied by the template arguments of the explicit instantiation*** ...
Comment 3 Patrick Palka 2020-07-11 16:47:17 UTC
Another testcase:

   template <int N>
   struct A {
       void f() requires (N == 3) { static_assert(N == 3); }
   };

   template struct A<2>;
Comment 4 GCC Commits 2020-07-30 02:15:12 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:dc3d1e181445fafbbd146eb355a750c41c338794

commit r11-2417-gdc3d1e181445fafbbd146eb355a750c41c338794
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jul 29 22:06:33 2020 -0400

    c++: constraints and explicit instantiation [PR96164]
    
    When considering to instantiate a member of a class template as part of
    an explicit instantiation of the class template, we need to first check
    the member's constraints before proceeding with the instantiation of the
    member.
    
    gcc/cp/ChangeLog:
    
            PR c++/96164
            * constraint.cc (constraints_satisfied_p): Return true if
            !flags_concepts.
            * pt.c (do_type_instantiation): Update a paragraph taken from
            [temp.explicit] to reflect the latest specification.  Don't
            instantiate a member with unsatisfied constraints.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/96164
            * g++.dg/cpp2a/concepts-explicit-inst5.C: New test.
Comment 5 GCC Commits 2020-08-11 02:36:05 UTC
The releases/gcc-10 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:215927a736d21d8cff8baeb50f687911a00149b9

commit r10-8602-g215927a736d21d8cff8baeb50f687911a00149b9
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jul 29 22:06:33 2020 -0400

    c++: constraints and explicit instantiation [PR96164]
    
    When considering to instantiate a member of a class template as part of
    an explicit instantiation of the class template, we need to first check
    the member's constraints before proceeding with the instantiation of the
    member.
    
    gcc/cp/ChangeLog:
    
            PR c++/96164
            * constraint.cc (constraints_satisfied_p): Return true if
            !flags_concepts.
            * pt.c (do_type_instantiation): Update a paragraph taken from
            [temp.explicit] to reflect the latest specification.  Don't
            instantiate a member with unsatisfied constraints.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/96164
            * g++.dg/cpp2a/concepts-explicit-inst5.C: New test.
    
    (cherry picked from commit dc3d1e181445fafbbd146eb355a750c41c338794)
Comment 6 Patrick Palka 2020-08-11 02:39:03 UTC
This should be fixed for GCC 10.3+, thanks for the report.
Comment 7 Andrew Pinski 2021-11-11 22:25:00 UTC
*** Bug 77595 has been marked as a duplicate of this bug. ***
Comment 8 Patrick Palka 2023-03-15 13:25:24 UTC
*** Bug 68608 has been marked as a duplicate of this bug. ***