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

             Bug #: 54541
           Summary: SFINAE bug: handling incomplete return types
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: ts...@mail.ru


g++ 4.8.0 20120909 (experimental) fails to compile the following well-defined
code:

    #include <utility>

    struct X;

    X f(int);

    template <class T>
        void g(decltype((void)f(std::declval<T>())) *)
    {}
    template <class T>
        void g(...)
    {}

    int main()
    {
        g<int>(0);
    }

COLLECT_GCC_OPTIONS='-v' '-std=c++11' '-shared-libgcc' '-mtune=generic'
'-march=pentiumpro'

test.cpp: In substitution of ‘template<class T> void g(decltype
((void)(f(declval<T>())))*) [with T = <missing>]’:
test.cpp:16:17:   required from here
test.cpp:8:50: error: invalid use of incomplete type ‘struct X’
         void g(decltype((void)f(std::declval<T>())) *)
                                                  ^
test.cpp:3:12: error: forward declaration of ‘struct X’
     struct X;
            ^

Compiler version info:

Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=../target --enable-languages=c,c++
Thread model: posix
GNU C++ (GCC) version 4.8.0 20120909 (experimental) (i686-pc-linux-gnu)
    compiled by GNU C version 4.8.0 20120909 (experimental), GMP version 5.0.2,
MPFR version 3.1.0, MPC version 0.8.2

Explanation:

When considering g<int>(0), for the former g the error [the expression
(void)f(std::declval<T>()) uses incomplete type X in a context where complete
type is required] occurs in immediate context (and there are no any errors in
non-immediate context), so the former g should be just excluded from the set of
candidate functions due to substitution failure. The latter g is the only
viable candidate, so it should be called.

Reply via email to