public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48078] New: gcc accepts-invalid: taking address of private member function from template function
@ 2011-03-11 17:27 cgd at google dot com
  2011-03-11 17:38 ` [Bug c++/48078] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: cgd at google dot com @ 2011-03-11 17:27 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: gcc accepts-invalid: taking address of private member
                    function from template function
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: cgd@google.com


test case (created by Bill Clarke):

class A {
 public:
 A() {}
 private:
 void APrivateMethod() { }
};

// Enable this to get a (correct) compiler error.
#if 0
void CallAPrivateMethod() {
 void (A::*fn)() = &A::APrivateMethod;
 A a;
 (a.*fn)();
}
#endif

template <typename T>
void CallAPrivateMethodTemplate() {
 void (A::*fn)() = &A::APrivateMethod;
 A a;
 (a.*fn)();
}

void CallAPrivateMethodViaTemplate() {
 CallAPrivateMethodTemplate<int>();
}


compiles successfully (incorrectly AFAIU) with pre-4.6 (4.6.0 20110311)
(I tested some versions of GCC back to 4.2.x, same problem.  They had local
mods, but none that should have caused a difference in this regard.)


FYI, clang C++ front-end flags an error as expected:

devtools/cpp_tests/x.cc:22:24: error: 'APrivateMethod' is a private member of
'A'
 void (A::*fn)() = &A::APrivateMethod;
                       ^
devtools/cpp_tests/x.cc:8:7: note: declared private here
 void APrivateMethod() { }
      ^
1 error generated.


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

end of thread, other threads:[~2021-08-04 11:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-11 17:27 [Bug c++/48078] New: gcc accepts-invalid: taking address of private member function from template function cgd at google dot com
2011-03-11 17:38 ` [Bug c++/48078] " redi at gcc dot gnu.org
2011-03-11 18:07 ` redi at gcc dot gnu.org
2011-03-11 19:59 ` cgd at google dot com
2011-05-11 10:52 ` redi at gcc dot gnu.org
2011-05-27 15:23 ` redi at gcc dot gnu.org
2021-08-04  5:45 ` [Bug c++/48078] " pinskia at gcc dot gnu.org
2021-08-04  5:47 ` pinskia at gcc dot gnu.org
2021-08-04 11:40 ` redi 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).