From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3F0E93858D28; Mon, 19 Sep 2022 17:13:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F0E93858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663607629; bh=V5SO99JlDsZhcaPaGaVhqk05pk12ytUhrFf792VxPmI=; h=From:To:Subject:Date:From; b=khUPWTKe7KSYRcBhopWcblvX7xAQ5ytz8t5V7WVx//kBL0LZH608Os1FUnnyD62CD hQLCS9stc/Tb20RpMI0fMfaPNcteeqVpw+QGXObtjc1RC64lAdkpizubKmHai1Wcvr O7ynsd2Iud8mrzyPPcBrq9HBY73ggV+ZGmvFjPVo= From: "enolan at alumni dot cmu.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106969] New: member function constness incorrectly propagates to local class member function return type deduction Date: Mon, 19 Sep 2022 17:13:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: enolan at alumni dot cmu.edu 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D106969 Bug ID: 106969 Summary: member function constness incorrectly propagates to local class member function return type deduction Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: enolan at alumni dot cmu.edu Target Milestone: --- When using decltype in the return type of a member function of a local class defined inside of a const member function, the type of 'this' seems to be deduced as a pointer to const, when it should be a pointer to non-const. Compiler explorer link: https://godbolt.org/z/9KKbrzq1e Minimal reproduction: struct Context { void action() const { struct { int wrapped; decltype( & wrapped ) get() { return &wrapped; } } t; *t.get()=3D 42; } }; Note that if the local class member function definition is changed to: auto get() -> decltype( & wrapped ) { return &wrapped; } Then the bug no longer appears. > the exact version of gcc gcc version 12.2.1 20220819 (Red Hat 12.2.1-2) (GCC) > the system type Fedora release 38 (Rawhide) > the options given when GCC was configured/built Configured with: ../configure --enable-bootstrap --enable-languages=3Dc,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=3D/usr --mandir=3D/usr/share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttp://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=3Dposix --enable-checking=3Drelease --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-linker-hash-style=3Dgnu --enable-plugin --enable-initfini-array --with-isl=3D/builddir/build/BUILD/gcc-12.2.1-20220819/obj-x86_64-redhat-li= nux/isl-install --enable-offload-targets=3Dnvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=3Dgeneric --with-arch_32=3Di686 --build=3Dx86_64-redhat-linux --with-build-config=3Dbootstrap-lto --enable-link-serialization=3D1 > the complete command line that triggers the bug g++ poc.cpp > the compiler output poc.cpp: In member function =E2=80=98void Context::action() const=E2=80=99: poc.cpp:12:17: error: assignment of read-only location =E2=80=98* t.Context= ::action() const::::get()=E2=80=99 12 | *t.get()=3D 42; | ~~~~~~~~^~~~=