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

           Summary: Wrong return type when applying address operator to
                    inherited, template dependend member, using a typedef
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: meinh...@uni-mainz.de


The following code should compile but does not. It works on any other compiler
I tried (Comeau, Intel and MSVC). It seems the espression "&(Super::data)" is
interpreted as a pointer-to-data-member. This interpretation cannot be correct,
because the braces would not be legal in that kind of expression.

A possible workaround is using "&(this->data)" instead.

Works as expected if done without templates.

Code:

template <typename T> struct foo
{
  T data;
};

template<typename T> struct bar: public foo<T>
{
  typedef foo<T> Super;
  void some_func()
  {
    T* ptr = & (Super::data);    
  }
};

int main()
{
  bar<int> b; 
  b.some_func();
}


Output:

$> g++ -v  -Wall -Wextra test.cc
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc
--disable-werror --with-arch-32=i486 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
COLLECT_GCC_OPTIONS='-v' '-Wall' '-Wextra' '-shared-libgcc' '-mtune=generic'
 /usr/lib/gcc/x86_64-linux-gnu/4.4.3/cc1plus -quiet -v -D_GNU_SOURCE test.cc
-D_FORTIFY_SOURCE=2 -quiet -dumpbase test.cc -mtune=generic -auxbase test -Wall
-Wextra -version -fstack-protector -o /tmp/ccqnK7Ea.s
GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (x86_64-linux-gnu)
    compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.4
 /usr/include/c++/4.4/x86_64-linux-gnu
 /usr/include/c++/4.4/backward
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include
 /usr/lib/gcc/x86_64-linux-gnu/4.4.3/include-fixed
 /usr/include
End of search list.
GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (x86_64-linux-gnu)
    compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 88858f45841827736473e527a4e9ab10
test.cc: In member function ‘void bar<T>::some_func() [with T = int]’:
test.cc:18:   instantiated from here
test.cc:11: error: cannot convert ‘int foo<int>::*’ to ‘int*’ in initialization
test.cc:11: warning: unused variable ‘ptr’

Reply via email to