From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D6E163857708; Tue, 23 May 2023 13:30:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6E163857708 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684848652; bh=Ejrbin4EQmQ3iJwusXkRwGs/pVZViPAz13puCdeNnX0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wakCpND4UiU5HHtM3VZQlWjZlC/53WOD/lChidLt6WG16EEzkZxxVV2n7+CO/OIF/ 46dadaaDyvonofeYi2aS42mPDm0XrrfY6J/5dEmgh63EDk5IOJveem53FcaL0zjb7a 2BZO2bxTBke/5kUR7g8/wbf1swByAguCafYnNW7Y= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109942] Function template declared extern is implicitly instantiated on -O optimization level when return type is auto Date: Tue, 23 May 2023 13:30:52 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109942 --- Comment #1 from Jonathan Wakely --- I think it's debatable whether GCC's behaviour is incorrect. The definition= of the function template can be seen, and no explicit specialization has been declared for foo, so the compiler is allowed to inline the definition. It *has* to instantiate it the definition, to determine the return type. Si= nce it has to instantiate it anyway, it might as well inline it as well. So even if this failed to link, you wouldn't get faster compile times becau= se the definition must be instantiated anyway.=