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

            Bug ID: 118382
           Summary: GCC fails to detect erroneous implicit template
                    argument specification in extern class declaration for
                    template class with default argument
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wangbopku15 at gmail dot com
  Target Milestone: ---

The following code seems to have some problems:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

template <typename=int>
struct D{};

extern D d;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In a template class declaration(not definition), the template arguments must be
explicitly specified, which means the '<>' specifier should not be eliminated
here. The correct version might be like:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

template <typename=int>
struct D{};

extern D<> d;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

EDG, Clang, and ICC reject the first one and accept the second, but GCC seems
to accept both:

https://godbolt.org/z/55b1vrrP5
  • [Bug c++/118382] New: GCC fails ... wangbopku15 at gmail dot com via Gcc-bugs

Reply via email to