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

            Bug ID: 58829
           Summary: non-static member initializer in nested template class
                    produces incorrect compile error
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lhyatt at gmail dot com

==========
struct A {
    int f() {return 0;}
} a;

struct B {
    template<int=0> struct C {
        int i = a.f();
    };
};
B::C<> c;
============

Above snippet is valid C++11, fails to compile with the following error:

t.cpp: In constructor 'constexpr B::C<>::C()':
t.cpp:7:21: error: no matching function for call to 'A::f(A*)'
         int i = a.f();
                     ^
t.cpp:7:21: note: candidate is:
t.cpp:2:9: note: int A::f()
     int f() {return 0;}
         ^
t.cpp:2:9: note:   candidate expects 0 arguments, 1 provided
t.cpp: At global scope:
t.cpp:10:8: note: synthesized method 'constexpr B::C<>::C()' first required
here
 B::C<> c;

If you make C a non-template, or remove the outer class B in which C is nested,
then it works OK. clang compiles it OK. I see it on 4.8.1 and on the current
svn mainline.

$ g++ -v -std=c++11 -o t.o -c t.cpp
Using built-in specs.
COLLECT_GCC=/usr/local/gcc48/bin/g++
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --enable-threads=posix --enable-__cxa_atexit
--prefix=/usr/local/gcc-4.8.1
Thread model: posix
gcc version 4.8.1 (GCC)
COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-o' 't.o' '-c' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/local/gcc-4.8.1/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/cc1plus -quiet
-v -D_GNU_SOURCE t.cpp -quiet -dumpbase t.cpp -mtune=generic -march=x86-64
-auxbase-strip t.o -std=c++11 -version -o /tmp/ccxl7AbU.s
GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 4.3.2, MPFR version 2.4.2-p1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1

/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/x86_64-unknown-linux-gnu

/usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include
 /usr/local/include
 /usr/local/gcc-4.8.1/include
 /usr/local/gcc-4.8.1/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 4.3.2, MPFR version 2.4.2-p1,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9381368e685e312c931bb6a2db2d568c
t.cpp: In constructor 'constexpr B::C<>::C()':
t.cpp:7:21: error: no matching function for call to 'A::f(A*)'
         int i = a.f();
                     ^
t.cpp:7:21: note: candidate is:
t.cpp:2:9: note: int A::f()
     int f() {return 0;}
         ^
t.cpp:2:9: note:   candidate expects 0 arguments, 1 provided
t.cpp: At global scope:
t.cpp:10:8: note: synthesized method 'constexpr B::C<>::C()' first required
here
 B::C<> c;
        ^

Reply via email to