https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69694

            Bug ID: 69694
           Summary: type incomplete depending if constructing function is
                    templated
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bloerwald at googlemail dot com
  Target Milestone: ---

Created attachment 37595
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37595&action=edit
source file triggering the bug when compiled with -DA

Depending on whether or not the function creating an object of Fun<Tag> is a
template or not, Fun<Tag> is either incomplete or not, in the snippet below. In
addition, once it is referenced from a non-templated function, it is no longer
incomplete in following templated functions.

  $ gcc/5.3.0/bin/g++ -fno-strict-aliasing -fwrapv -W -Wall -Werror -Wextra
-std=c++11 -c snippet.cpp -DA
  snippet.cpp: In function ‘void a()’:
  snippet.cpp:24:44: error: invalid use of incomplete type ‘struct Fun<Tag>’
     template<typename> void a() { Fun<Tag> {}.fun(); }
                                              ^
  snippet.cpp:8:46: note: declaration of ‘struct Fun<Tag>’
     template<typename, typename = void> struct Fun;

The definitions -DA, -DB, -DC can be used to demonstrate the effect of "once
referenced from non-templated" described above:

  -DA: a fails
  -DB: success
  -DC: c fails

  -DA -DB: a fails
  -DA -DC: a and c fail
  -DB -DC: success (c is fine!)

  -DA -DB -DC: a fails, c is fine

Also fails with gcc 4.9.2, succeeds with clang 3.5.1/3.7.1.

Replacing `void fun();` with `void operator()();` and the calls with
`Fun<Tag>{}();` lets the error message degrade to "no match for call to
‘(Fun<Tag>) ()’" (note the braces around Fun<Tag>).

Reply via email to