Bug 59033 - cannot control inherited constructors access
Summary: cannot control inherited constructors access
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-06 21:07 UTC by Akim Demaille
Modified: 2013-11-07 12:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Akim Demaille 2013-11-06 21:07:45 UTC
Hi,

Again, I have found no clear wording in the draft of the standard that I have, however, consistency in the language would expect that "using" to import constructors should provide them with the _current_ public/protected/private visibility, not the one of the original constructor.

The following example shows that the "using" on types and "using" on constructors are not treated the same way.

akim@padam /tmp $ cat foo.cc
struct base
{
protected:
  using type = int;
  base(type, type) {}
};

struct derived: public base
{
public:
  using base::base;
  using base::type;
};

int main()
{
  derived::type i;
  derived b(i,i);
}
akim@padam /tmp $ g++-mp-4.9 -Wall -std=c++11 foo.cc
foo.cc: In function 'int main()':
foo.cc:11:15: error: 'derived::derived(base::type, base::type)' is protected
   using base::base;
               ^
foo.cc:18:16: error: within this context
   derived b(i,i);
                ^
akim@padam /tmp $ g++-mp-4.9 --version
g++-mp-4.9 (MacPorts gcc49 4.9-20130915_0) 4.9.0 20130915 (experimental)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Same with 4.8.
Comment 1 Paolo Carlini 2013-11-07 09:50:17 UTC
visibility is a term of art
Comment 2 Daniel Krügler 2013-11-07 12:00:44 UTC
The wording in the standard is pretty clear (12.9 p4):

"A constructor so declared has the same access as the corresponding constructor in X."

The gcc compiler (and clang as well) both behave according to this specification.

A using declaration for a type is different: There can not be two (or more) types of the same name within such a using declaration.
Comment 3 Paolo Carlini 2013-11-07 12:12:00 UTC
Closing then.