From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24348 invoked by alias); 23 Aug 2012 13:42:18 -0000 Received: (qmail 24336 invoked by uid 22791); 23 Aug 2012 13:42:16 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 23 Aug 2012 13:41:59 +0000 From: "bruno-gcc at defraine dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class Date: Thu, 23 Aug 2012 13:42:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bruno-gcc at defraine dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-08/txt/msg01623.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359 Bug #: 54359 Summary: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: bruno-gcc@defraine.net Even after closing bug #49003, there remain problems regarding the handling of N3282 (resolution of DR 1207). Specifically, the problems have to do with a definition of a member function outside of the class. Consider these test cases: int& ref(int& x) { return x; } const int& ref(const int& x) { return x; } class A { int x; int f() const; auto test1() const -> decltype(this); auto test2() const -> decltype(ref(x)); auto test3() const -> decltype(f()); }; auto A::test1() const -> decltype(this) { return this; } auto A::test2() const -> decltype(ref(x)) { return ref(x); } auto A::test3() const -> decltype(f()) { return f(); } This gives the following compiler errors in the C++0x mode of gcc 4.7.1: - test1(): invalid use of 'this' at top level - test2(): prototype for 'int& A::test2() const' does not match any in class 'A' (candidate is: const int& A::test2() const); additionally, 'int A::x' is private - test3(): cannot call member function 'int A::f() const' without object; additionally, 'int A::f() const' is private In summary, in the trailing return type of a const member function definition outside of a class declaration, it seems: 1. I cannot explicitly reference 'this' 2. I can reference data members, but not private ones, and they are not const 3. I cannot invoke member functions I believe all three function definitions should compile. Similarly, inline definitions of the same member functions have no such problems: class B { int x; int f() const; auto test1() const -> decltype(this) { return this; } auto test2() const -> decltype(ref(x)) { return ref(x); } auto test3() const -> decltype(f()) { return f(); } }; It seems that issue #2 is a regression compared to gcc 4.6, which seemed to allow some access to data members. Consider test4(): template class C { const X& x; auto test4() const -> decltype(x); }; template auto C::test4() const -> decltype(x) { return x; } This test compiles without problems under gcc 4.6.3. Whereas gcc 4.7.1 gives: prototype for 'decltype (((C*)0)->C::x) C::test4() const' does not match any in class 'C' (candidate is: decltype (((const C*)this)->C::x) C::test4() const)