First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 40843
Product:  
Component:  
Status: UNCONFIRMED
Resolution:
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Alexander Osipenko <sipych@gmail.com>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 40843 depends on: Show dependency tree
Show dependency graph
Bug 40843 blocks:

Additional Comments:






Mark bug as waiting for feedback



    

    

View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2009-07-23 21:41
// Illegal access to private member not detected, program compiles silently.
// bug found in:
// g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
// g++ (Ubuntu 4.3.3-5ubuntu4) 4.3.3
#include <iostream>

class A {
enum { value=1 };       // private
};

template <int i>        // bug appears only if B is a template
struct B {
 enum { value=A::value }; // <- silently access private member
};

int main() {
  std::cout << B<1>::value << std::endl;
  return 0;
}

------- Comment #1 From Andrew Pinski 2009-07-23 21:46 -------
I think this is a duplicate of bug 21008.

------- Comment #2 From Alexander Osipenko 2009-07-23 22:08 -------
(In reply to comment #1)
> I think this is a duplicate of bug 21008.
> 

Not shure, A::value may not be accessible neither at the template definition,
nor at the instantiation time.

------- Comment #3 From Alexander Osipenko 2009-07-23 22:46 -------
Also present in gcc 4.4.0

------- Comment #4 From Alexander Osipenko 2009-07-24 00:00 -------
// More similar cases. Static members also may be accessed

#include <iostream>

class A {
enum { value=1 };       // private
static const int ci=2;
static int fi() { return 3; }
};

template <int i>        // bug appears only if B is a template
struct B {
 enum { value=A::value }; // <- silently access private member
// enum { v2=A::ci  };    // this error is detected @ any instantiation 
 static const int v3=A::value;          // not detected
 static const int v4=A::ci;             // not detected
 static int f5() { return A::value; }   // not detected
 static int f6() { return A::ci; }      // detected only if f6() accessed
 static int f7() { return A::fi(); }    // detected only if f7() accessed,
reported twice
};

int main() {
  std::cout << B<1>::value << B<1>::v3 << B<1>::v4 << B<1>::f5() 
// << B<1>::f6()        // error will be detected
// << B<1>::f7()        // error will be detected, and reported TWICE
   << std::endl;
  return 0;
}

First Last Prev Next    No search results available      Search page      Enter new bug