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

            Bug ID: 123844
           Summary: Function default arguments cause template
                    instantiation
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bolsh.andrey at yandex dot ru
  Target Milestone: ---

GCC reports an error due to incomplete type for the following code:

class Incomplete;

template <class T>
T* getPtr() {
    return new T;
}

void Fn(Incomplete* = getPtr<Incomplete>());

I think it is wrong because it is stated in [temp.inst] p.9:

The use of a template specialization in a default argument shall not cause the
template to be implicitly instantiated except that a class template may be
instantiated where its complete type is needed to determine the correctness of
the default argument. The use of a default argument in a function call causes
specializations in the default argument to be implicitly instantiated.

https://timsong-cpp.github.io/cppwp/n4659/temp.inst#9

Clang and MSVC both compile such code: https://godbolt.org/z/dcjenvxxT
  • [Bug c++/123844] New: Function ... bolsh.andrey at yandex dot ru via Gcc-bugs

Reply via email to