From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4004B385800D; Tue, 15 Dec 2020 01:13:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4004B385800D From: "wuyongwei at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98283] New: decltype(auto) may be deduce static data member to wrong type Date: Tue, 15 Dec 2020 01:13:57 +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: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: wuyongwei at gmail 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: 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 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: Tue, 15 Dec 2020 01:13:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98283 Bug ID: 98283 Summary: decltype(auto) may be deduce static data member to wrong type Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wuyongwei at gmail dot com Target Milestone: --- The following code shows that `decltype(auto)` is deduced to the wrong type when used in template code for an expression like `(var.static_data_member>= )`. ```cpp #include #include #include template struct type_displayer; #define TYPE_DISPLAY(x) type_displayer test_obj; struct SkipField {}; struct TestSkip { template struct FIELD; int value; static SkipField unused; template struct FIELD { T &&obj; FIELD(T &&ref) : obj(std::forward(ref)) { } decltype(auto) value() { return (obj.value); } static constexpr const char *name() { return "value"; } }; template struct FIELD { T &&obj; FIELD(T &&ref) : obj(std::forward(ref)) { } decltype(auto) value() { return (obj.unused); } decltype((obj.unused)) valueAlt() { return (obj.unused); } static constexpr const char *name() { return "unused"; } }; }; int main() { TestSkip s; // decltype((TestSkip::FIELD(s).value())) is int& // decltype((TestSkip::FIELD(s).value())) is SkipField, but it should be SkipField& // decltype((TestSkip::FIELD(s).valueAlt())) is SkipField& } ``` This is a simplified usage scenario, where I want to use a macro to generate code to emulate static reflection. Here is the problematic part: ```cpp decltype(auto) value() { return (obj.unused); } ``` This function returns `SkipField`, instead of the expected `SkipField&`. I = have verified that clang does what I want. Currently I have to avoid `decltype(auto)` as a workaround: ```cpp decltype((obj.unused)) valueAlt() { return (obj.unused); } ``` (I used the macro TYPE_DISPLAY to check the type of an expression.)=