Bug 52816 - [C++11] Access to private members inside decltype in the signature of a member template causes access control error
Summary: [C++11] Access to private members inside decltype in the signature of a membe...
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: rejects-valid
Depends on:
Reported: 2012-04-01 07:32 UTC by Jeremiah Willcock
Modified: 2013-07-22 16:20 UTC (History)
2 users (show)

See Also:
Known to work: 4.8.0
Known to fail: 4.7.3
Last reconfirmed: 2012-06-15 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Jeremiah Willcock 2012-04-01 07:32:56 UTC
When using decltype inside the return type of a member function template, I receive access control errors for references to private member variables.  Here is a simple example of a failing program:

class c {
  int f;
  template <typename A>
  decltype(f) m(A) const;

decltype(c{}.m(0)) i;

The use of old- vs. new-style function declarations does not change the behavior; neither does whether the class itself is a template.  The error I get from GCC 4.7.0 is:

test.cpp:2:7: error: ‘int c::f’ is private
test.cpp:8:20: error: within this context

I think that is likely to be incorrect since the reference to f is from inside the body of the class definition itself.
Comment 1 Jonathan Wakely 2012-06-15 18:43:38 UTC
Comment 2 Jonathan Wakely 2012-08-24 11:54:54 UTC
This compiles OK with trunk
Comment 3 Jonathan Wakely 2012-11-07 19:09:01 UTC
Jason, is this worth fixing for 4.7 or should we just close it as fixed on the trunk?
Comment 4 Paolo Carlini 2013-07-22 16:02:28 UTC
Let's add the testcase and close the issue as fixed for 4.8.0.
Comment 5 Paolo Carlini 2013-07-22 16:20:32 UTC