From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2E9D939AD85F; Fri, 7 May 2021 13:15:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E9D939AD85F From: "StevenSun2021 at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99686] ICE when using both concepts and full specialization Date: Fri, 07 May 2021 13:15:16 +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: 11.1.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: StevenSun2021 at hotmail dot com X-Bugzilla-Status: UNCONFIRMED 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: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 May 2021 13:15:17 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99686 --- Comment #7 from Steven Sun --- After digging for two days, I think I may know what's happening inside.=20 Under std=3Dc++20 and my code in comment 1, the flow when parsing a full fu= nction specialization would be 1. Found a full specialization of function. 2. Instantiate all possible primary function templates.=20 3. Find the most suitable instantiation (here, the concept constrained is chosen) 4. Then replace it with full specialization. (this is done in `reregister_specialization` in `gcc/cp/pt.c`) So when performing overloading in the main function, there would be one instantiation and one full specialization to choose. (To be specific, those= two are in the hash table `decl_specialization` defined in `gcc/cp/pt.c`) While in the c++17 mode, step 4 is broken. So there will be 2 implicit instantiation to choose when overloading. Step 4 is performed in the function `duplicate_decls` defined in `gcc/cp/decl.c`. Certain conditions must be satisfied to replace the instantiation. The one failed here is: "the compiler thinks the full specialization has a different concepts constraint with primary template (because the primary template has contrain= ts but the full specialization doesn't)"=20 So the reregistration is never triggered. This is the source of the bug. After getting the whole picture, I simplify the test case as https://godbolt.org/z/9MM6rEf77 ----------------------- std=3Dc++17 -fconcepts template requires requires(T t) { ++t; } void func(T &&arg) { } template <> void func(int&& arg) { } int main() { func(1); } ----------------------- I'll give more details in the next comment in case any developer would like= to fix it.=