Bug 52620

Summary: using cannot import types in (non direct) base classes
Product: gcc Reporter: Akim Demaille <akim.demaille>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: akim.demaille
Priority: P3    
Version: 4.7.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: Test case

Description Akim Demaille 2012-03-19 15:55:59 UTC
Created attachment 26919 [details]
Test case

I might be missing something, sorry if this is just noise.  It looks
very much like http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51971 ,
but instead of "using" from the immediate base class, it fails when
"using" from a grand-child.  I checked the standard, and according to
_my_ reading it should work, yet this case is not presented as an example.

Please note that neither "using" in "bot" work.  I have left both of
them, but of course one should suffice.  It is interesting to note that
both are accepted (g++ does not report the "using" declarations as
errors - except for the duplication), yet it seems impossible to use
the imported name.

Thanks!


$ g++-mp-4.7 -std=c++0x -Wall foo.cc
foo.cc:18:3: error: 'type' does not name a type
foo.cc: In instantiation of 'struct bot<bool>':
foo.cc:28:13:   required from here
foo.cc:17:26: error: redeclaration of 'using med<bool>::type'
foo.cc:16:14: note: previous declaration 'using top::type'
foo.cc: In function 'int main()':
foo.cc:26:19: warning: unused variable 'vm' [-Wunused-variable]
foo.cc:30:19: warning: unused variable 'vb' [-Wunused-variable]

$ g++-mp-4.7 --version
g++-mp-4.7 (GCC) 4.7.0 20120225 (experimental)
Copyright (C) 2012 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.



$ g++-4.2  -Wall foo.cc
foo.cc:18: error: ‘type’ does not name a type
foo.cc: In function ‘int main()’:
foo.cc:26: warning: unused variable ‘vm’
foo.cc:30: warning: unused variable ‘vb’

$ g++-4.2  --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 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.



FWIW, clang 3.1 accepts both versions (using from top or from med<T>).


PS/  It is extremely confusing to be submit possible "duplicates"
that are not even C++ :(
Comment 1 Jonathan Wakely 2012-03-19 16:10:08 UTC
template <typename T>
struct bot: med<T>
{
  using top::type;

This is not valid, med<T> is a dependent base class so name lookup never looks in it, so top is not known to be a base class.

If you remove that line G++ accepts the code.


> PS/  It is extremely confusing to be submit possible "duplicates"
> that are not even C++ :(

I assume you mean the list of possible dups when filling in the form?
Your "C++" bug might actually be a middle-end bug, or a preprocessor bug, or something else, so it makes sense to look for dups across the whole database.
Comment 2 Akim Demaille 2012-03-19 16:16:37 UTC
(I pasted the wrong bug report, I meant http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21484)

(In reply to comment #1)
> template <typename T>
> struct bot: med<T>
> {
>   using top::type;
> 
> This is not valid, med<T> is a dependent base class so name lookup never looks
> in it, so top is not known to be a base class.

Ah, thanks for the clarification!

> If you remove that line G++ accepts the code.

Ah, somehow I broke my tests.  4.6.3 does not accept it (and is the compiler
I am actually using), but you are right that 4.7.0 is fine with it.

> > PS/  It is extremely confusing to be submit[ted] possible "duplicates"
> > that are not even C++ :(
> 
> I assume you mean the list of possible dups when filling in the form?
> Your "C++" bug might actually be a middle-end bug, or a preprocessor bug, or
> something else, so it makes sense to look for dups across the whole database.

Candidates were about Java :)  But I understand, thanks.
Comment 3 Jonathan Wakely 2012-03-19 16:31:04 UTC
(In reply to comment #2)
> (I pasted the wrong bug report, I meant
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21484)

That's a dup of PR 14258 so should be fixed for 4.7, and I think this is the same issue.


> (In reply to comment #1)
> > template <typename T>
> > struct bot: med<T>
> > {
> >   using top::type;
> > 
> > This is not valid, med<T> is a dependent base class so name lookup never looks
> > in it, so top is not known to be a base class.
> 
> Ah, thanks for the clarification!

I believe it's a bug in clang if it accepts it.


> > If you remove that line G++ accepts the code.
> 
> Ah, somehow I broke my tests.  4.6.3 does not accept it (and is the compiler
> I am actually using), but you are right that 4.7.0 is fine with it.

Yes, the 'using' code was significantly improved for 4.7, see the release notes at http://gcc.gnu.org/gcc-4.7/changes.html#cxx

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