public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43465]  New: access to private function as template argument depends on pointer syntax
@ 2010-03-21 10:08 oschmidt_do_not_send_email_to_this_address at gmx dot de
  2010-03-21 10:10 ` [Bug c++/43465] " oschmidt_do_not_send_email_to_this_address at gmx dot de
  0 siblings, 1 reply; 3+ messages in thread
From: oschmidt_do_not_send_email_to_this_address at gmx dot de @ 2010-03-21 10:08 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4262 bytes --]

Hi,

if a private static method is passed as a template argument, the visibility
depends whether pointer syntax is used or not. 

A simple example (more complex ones in attachment):

// ======================================================
#include <iostream>

typedef int F(int i);

template<F* f> class Class1
{
public:
    Class1() {
        std::cout << "Class1:" 
                  << (*f)(1) << "\n"; // <- the compiler complains here
               // <<   f (1) << "\n";    <- this one works!
    }
};

class Class2
{
public:
    Class2() {
        Class1<&m> a;
    }

private:
    static int m(int i) {
        return i + 1;
    }
};

int main()
{
    Class2 c;
    return 0;
}
// ======================================================


gives the compiler error:

test.cpp: In constructor ‘Class1<f>::Class1() [with int (* f)(int) =
Class2::m]’:
test.cpp:20:   instantiated from here
test.cpp:24: error: ‘static int Class2::m(int)’ is private
test.cpp:10: error: within this context

If (*f)(1) is replaced with f(1) the compiler accepts the code.

I examined more variations of this code pattern and have written three test
programs with various compiler switches that turn on or off pointer syntax and
I also included shell scripts to invoke the compiler with all permutations of
the switches, see attachment.

Command:   CXX=g++-4.4.3 sh classtest01.sh
Output:
 0 0 0 --> 0
 0 0 1 --> 0
 0 1 0 --> private
 0 1 1 --> private
 1 0 0 --> 0
 1 0 1 --> 0
 1 1 0 --> private
 1 1 1 --> private

Explanation: In this example there are three compiler switches to turn on of
off pointer syntax, the switches are printed at the beginning of the line (e.g.
"0 0 0" means: no pointer syntax). After the "-->" the return code of the
compiler invocation is printed (0 is ok). If the compiler error message
indicates that there is an access problem because the member is private, the
word "private" is printed after the "-->".

So the first test indicates that there are 4 syntax combinations where the
compiler doesn't compile the code.

Command: CXX=g++-4.4.3 sh functiontest01.sh
Output:
 0 0 0 --> 0
 0 0 1 --> 0
 0 1 0 --> private
 0 1 1 --> private
 1 0 0 --> 0
 1 0 1 --> 0
 1 1 0 --> private
 1 1 1 --> private

Now a more complex example:

Command: CXX=g++-4.4.3 sh functiontest02.sh
Output:
 0 0 0 0 0 --> 0
 0 0 0 0 1 --> 0
 0 0 0 1 0 --> 0
 0 0 0 1 1 --> 0
 0 0 1 0 0 --> 1
 0 0 1 0 1 --> 1
 0 0 1 1 0 --> 1
 0 0 1 1 1 --> 1
 0 1 0 0 0 --> private
 0 1 0 0 1 --> private
 0 1 0 1 0 --> private
 0 1 0 1 1 --> private
 0 1 1 0 0 --> 1
 0 1 1 0 1 --> 1
 0 1 1 1 0 --> 1
 0 1 1 1 1 --> 1
 1 0 0 0 0 --> 0
 1 0 0 0 1 --> 0
 1 0 0 1 0 --> 0
 1 0 0 1 1 --> 0
 1 0 1 0 0 --> 1
 1 0 1 0 1 --> 1
 1 0 1 1 0 --> 1
 1 0 1 1 1 --> 1
 1 1 0 0 0 --> private
 1 1 0 0 1 --> private
 1 1 0 1 0 --> private
 1 1 0 1 1 --> private
 1 1 1 0 0 --> 1
 1 1 1 0 1 --> 1
 1 1 1 1 0 --> 1
 1 1 1 1 1 --> 1

Explanation: Returncode 1 indicates another compiler error:
functiontest02.cpp: In function ‘void function1(int) [with int (* f)(int) =
Class2::m]’:
functiontest02.cpp:71:   instantiated from here
functiontest02.cpp:57: error: lvalue required as unary ‘&’ operand

All of the above examples and *all* combinations compile with return code 0 to
a correct program with expected bahaviour if one of the following compilers is
used: 

a) Intel:     icc (ICC) 11.1 20100203
b) Microsoft: cl  32-bit C/C++ Version 15.00.30729.01 for 80x86

IMHO all of the examples and all combinations are valid C++ code. However I may
be wrong ;-) Anyway it seems strange that the access refusal to private methods
as template arguments depends whether pointer syntax is used or not.

Best regards,
Oliver


-- 
           Summary: access to private function as template argument depends
                    on pointer syntax
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: oschmidt_do_not_send_email_to_this_address at gmx dot de
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug c++/43465] access to private function as template argument depends on pointer syntax
  2010-03-21 10:08 [Bug c++/43465] New: access to private function as template argument depends on pointer syntax oschmidt_do_not_send_email_to_this_address at gmx dot de
@ 2010-03-21 10:10 ` oschmidt_do_not_send_email_to_this_address at gmx dot de
  0 siblings, 0 replies; 3+ messages in thread
From: oschmidt_do_not_send_email_to_this_address at gmx dot de @ 2010-03-21 10:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from oschmidt_do_not_send_email_to_this_address at gmx dot de  2010-03-21 10:10 -------
Created an attachment (id=20150)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20150&action=view)
testcode and compiler invocation scripts


-- 


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


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

* [Bug c++/43465] access to private function as template argument depends on pointer syntax
       [not found] <bug-43465-4@http.gcc.gnu.org/bugzilla/>
@ 2021-07-27  6:14 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27  6:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43465

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|i686-pc-linux-gnu           |
              Build|i686-pc-linux-gnu           |
               Host|i686-pc-linux-gnu           |
         Resolution|---                         |DUPLICATE
           Keywords|                            |rejects-valid
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |8.0

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 8+

This is a dup of bug 22149.

*** This bug has been marked as a duplicate of bug 22149 ***

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

end of thread, other threads:[~2021-07-27  6:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-21 10:08 [Bug c++/43465] New: access to private function as template argument depends on pointer syntax oschmidt_do_not_send_email_to_this_address at gmx dot de
2010-03-21 10:10 ` [Bug c++/43465] " oschmidt_do_not_send_email_to_this_address at gmx dot de
     [not found] <bug-43465-4@http.gcc.gnu.org/bugzilla/>
2021-07-27  6:14 ` pinskia 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).