public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58954] New: accessing a private member function in decltype of a friend class causes access control error
@ 2013-11-01  4:16 myspam456 at gmail dot com
  2013-11-01  6:53 ` [Bug c++/58954] " daniel.kruegler at googlemail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: myspam456 at gmail dot com @ 2013-11-01  4:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58954
           Summary: accessing a private member function in decltype of a
                    friend class causes access control error
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: myspam456 at gmail dot com

When trying to use decltype on a member function which has a late specified
return type calling a private member function of a friend class I receive the
below error.  My understanding is that the "friend struct base<derived>;" in
derived should cause this error to not occur which is the case with clang.  

Adding "foo_argument<derived>" does cause the error to disappear.  

I apologize for the length of the example, but I've had difficulty reproducing
it with fewer lines of code.

main.cpp: In instantiation of ‘struct foo_argument<derived>’:
main.cpp:43:47:   required from here
main.cpp:9:50: error: no matching function for call to
‘foo_argument<derived>::test(<unresolved overloaded function type>)’
     using type = decltype(test(&T::template foo<>));
                                                  ^
main.cpp:9:50: note: candidate is:
main.cpp:7:16: note: template<class Ret, class C, class Arg> static Arg
foo_argument<T>::test(Ret (C::*)(Arg)) [with Ret = Ret; C = C; Arg = Arg; T =
derived]
     static Arg test(Ret (C::*)(Arg));
                ^
main.cpp:7:16: note:   template argument deduction/substitution failed:
main.cpp:35:9: error: ‘int derived::foo_impl(int)’ is private
     int foo_impl(int i)
         ^
main.cpp:9:50: error: within this context
     using type = decltype(test(&T::template foo<>));

The below example can be seen at:
http://coliru.stacked-crooked.com/a/3ffd6557434a3ab9

#include <utility>

template<class T>
struct foo_argument
{
    template<class Ret, class C, class Arg>
    static Arg test(Ret (C::*)(Arg));

    using type = decltype(test(&T::template foo<>));
};

template<class T, class D>
struct dependent { typedef T type; };

template<class T, class D>
using Dependent = typename dependent<T, D>::type;

template<class T>
struct base
{
    friend struct foo_argument<T>;

    template<class Ignore = void>
    auto foo(int i) -> decltype(std::declval<Dependent<T&,
Ignore>>().foo_impl(i))
    {
        return static_cast<T&>(*this).foo_impl(i);
    }
};

struct derived : base<derived>
{
    friend struct base<derived>;
    //friend struct foo_argument<derived>;
  private:
    int foo_impl(int i)
    {
        return 123 + i;
    }
};

int main()
{
    using foo_arg_type = foo_argument<derived>::type;
}
>From gcc-bugs-return-433230-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Nov 01 04:55:07 2013
Return-Path: <gcc-bugs-return-433230-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 3608 invoked by alias); 1 Nov 2013 04:55:07 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 3561 invoked by uid 48); 1 Nov 2013 04:55:03 -0000
From: "su at cs dot ucdavis.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/58955] New: wrong code at -O3 on x86_64-linux-gnu
Date: Fri, 01 Nov 2013 04:55:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: su at cs dot ucdavis.edu
X-Bugzilla-Status: UNCONFIRMED
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
Message-ID: <bug-58955-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-11/txt/msg00007.txt.bz2
Content-length: 1506

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX955

            Bug ID: 58955
           Summary: wrong code at -O3 on x86_64-linux-gnu
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu

The current gcc trunk miscompiles the following testcase on x86_64-linux-gnu at
-O3 (in both 32-bit and 64-bit modes).

This is a regression from 4.8.x.

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure
--enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-werror
--enable-checking=none --with-gmp=/usr/local/gcc-trunk
--with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk
--with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk
Thread model: posix
gcc version 4.9.0 20131031 (experimental) [trunk revision 204248] (GCC)
$
$ gcc-trunk -O2 small.c; a.out
1
$ gcc-4.8 -O3 small.c; a.out
1
$ gcc-trunk -O3 small.c; a.out
0
$

------------------------------------


int printf (const char *, ...);

int a, b, c, d[4] = { 0, 0, 0, 1 };

int
main ()
{
  for (; a < 4; a++)
    {
      int e = d[a];
      for (c = 1; c < 1; c++);
      b = e;
      d[a] = 0;
    }
  printf ("%d\n", b);
  return 0;
}


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

end of thread, other threads:[~2013-12-27 22:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-01  4:16 [Bug c++/58954] New: accessing a private member function in decltype of a friend class causes access control error myspam456 at gmail dot com
2013-11-01  6:53 ` [Bug c++/58954] " daniel.kruegler at googlemail dot com
2013-11-01 11:33 ` [Bug c++/58954] [4.8/4.9 Regression] " paolo.carlini at oracle dot com
2013-11-01 11:36 ` paolo.carlini at oracle dot com
2013-11-19  9:51 ` rguenth at gcc dot gnu.org
2013-12-13  3:41 ` jason at gcc dot gnu.org
2013-12-13  3:58 ` jason at gcc dot gnu.org
2013-12-13  3:59 ` jason at gcc dot gnu.org
2013-12-27 22:06 ` 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).