public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class
@ 2012-08-23 13:42 bruno-gcc at defraine dot net
  2012-08-24  0:30 ` [Bug c++/54359] " paolo.carlini at oracle dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: bruno-gcc at defraine dot net @ 2012-08-23 13:42 UTC (permalink / raw)
  To: gcc-bugs

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<typename X>
class C {
    const X& x;
    auto test4() const -> decltype(x);
};

template<typename X>
auto C<X>::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<X>*)0)->C<X>::x) C<X>::test4() const' does not
match any in class 'C<X>' (candidate is: decltype (((const
C<X>*)this)->C<X>::x) C<X>::test4() const)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/54359] [C++0x][N3282] decltype in member function's trailing return type when defined outside of class
  2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
@ 2012-08-24  0:30 ` paolo.carlini at oracle dot com
  2012-08-24 12:10 ` [Bug c++/54359] [C++0x] " redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-08-24  0:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-08-24 00:29:39 UTC ---
I'm wondering if we shouldn't just have a metabug for decltype and one for
lambdas... looking for volunteers (Daniel? ;)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/54359] [C++0x] decltype in member function's trailing return type when defined outside of class
  2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
  2012-08-24  0:30 ` [Bug c++/54359] " paolo.carlini at oracle dot com
@ 2012-08-24 12:10 ` redi at gcc dot gnu.org
  2012-08-24 12:21 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2012-08-24 12:10 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-08-24 12:10:26 UTC ---
Done, see PR 54366 and PR 54367 (I probably missed some that could be added to
the meta bugs)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/54359] [C++0x] decltype in member function's trailing return type when defined outside of class
  2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
  2012-08-24  0:30 ` [Bug c++/54359] " paolo.carlini at oracle dot com
  2012-08-24 12:10 ` [Bug c++/54359] [C++0x] " redi at gcc dot gnu.org
@ 2012-08-24 12:21 ` paolo.carlini at oracle dot com
  2013-03-11  3:05 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-08-24 12:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paolo.carlini at oracle dot
                   |                            |com

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-08-24 12:21:21 UTC ---
Great. I'm adding to the decltype one 16375 too to be safe, but it's worth
another look.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/54359] [C++0x] decltype in member function's trailing return type when defined outside of class
  2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
                   ` (2 preceding siblings ...)
  2012-08-24 12:21 ` paolo.carlini at oracle dot com
@ 2013-03-11  3:05 ` jason at gcc dot gnu.org
  2013-03-17  2:40 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-11  3:05 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2013-03-11
                 CC|                            |jason at gcc dot gnu.org
         AssignedTo|unassigned at gcc dot       |jason at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/54359] [C++0x] decltype in member function's trailing return type when defined outside of class
  2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
                   ` (3 preceding siblings ...)
  2013-03-11  3:05 ` jason at gcc dot gnu.org
@ 2013-03-17  2:40 ` jason at gcc dot gnu.org
  2013-03-18  3:41 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-17  2:40 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-17 02:38:34 UTC ---
Author: jason
Date: Sun Mar 17 02:38:21 2013
New Revision: 196740

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196740
Log:
    PR c++/54359
    * parser.c (cp_parser_direct_declarator): Fix late return
    for out-of-class defn of member function.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/trailing8.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/54359] [C++0x] decltype in member function's trailing return type when defined outside of class
  2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
                   ` (4 preceding siblings ...)
  2013-03-17  2:40 ` jason at gcc dot gnu.org
@ 2013-03-18  3:41 ` jason at gcc dot gnu.org
  2013-03-26 14:28 ` jason at gcc dot gnu.org
  2014-03-04 22:16 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-18  3:41 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-18 03:41:18 UTC ---
Author: jason
Date: Mon Mar 18 03:41:10 2013
New Revision: 196765

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196765
Log:
    PR c++/54359
    PR c++/56639
    * parser.c (cp_parser_direct_declarator): Bail if we see a
    qualified-id not at namespace scope.

Added:
    trunk/gcc/testsuite/g++.dg/template/arrow2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/g++.dg/parse/typename7.C


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/54359] [C++0x] decltype in member function's trailing return type when defined outside of class
  2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
                   ` (5 preceding siblings ...)
  2013-03-18  3:41 ` jason at gcc dot gnu.org
@ 2013-03-26 14:28 ` jason at gcc dot gnu.org
  2014-03-04 22:16 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2013-03-26 14:28 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.8.1

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2013-03-26 14:28:45 UTC ---
Fixed for 4.8.1.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/54359] [C++0x] decltype in member function's trailing return type when defined outside of class
  2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
                   ` (6 preceding siblings ...)
  2013-03-26 14:28 ` jason at gcc dot gnu.org
@ 2014-03-04 22:16 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2014-03-04 22:16 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54359

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Tue Mar  4 22:16:03 2014
New Revision: 208332

URL: http://gcc.gnu.org/viewcvs?rev=208332&root=gcc&view=rev
Log:
    PR c++/60415
    PR c++/54359
    * parser.c (cp_parser_direct_declarator): Set declarator to
    cp_error_declarator on invalid qualified-id.

Added:
    trunk/gcc/testsuite/g++.dg/parse/ambig8.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-03-04 22:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-23 13:42 [Bug c++/54359] New: [C++0x][N3282] decltype in member function's trailing return type when defined outside of class bruno-gcc at defraine dot net
2012-08-24  0:30 ` [Bug c++/54359] " paolo.carlini at oracle dot com
2012-08-24 12:10 ` [Bug c++/54359] [C++0x] " redi at gcc dot gnu.org
2012-08-24 12:21 ` paolo.carlini at oracle dot com
2013-03-11  3:05 ` jason at gcc dot gnu.org
2013-03-17  2:40 ` jason at gcc dot gnu.org
2013-03-18  3:41 ` jason at gcc dot gnu.org
2013-03-26 14:28 ` jason at gcc dot gnu.org
2014-03-04 22:16 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).