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

            Bug ID: 58071
           Summary: Premature instantiation of default argument
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rogero at howzatt dot demon.co.uk

If a function is declared with a default argument of a template type the
compiler fails if the constructor cannot be instantiated at the point of
definition of the function.

As I understand it 8.3.6p5 states "The names in the default argument are
bound, and the semantic constraints are checked, at the point where the default
argument appears."

So the compiler can instantiate the *class* definition but I do not believe it
should be instantiating the constructor body unless and until the default
argument is actually *used*.

The code below compiles and links with Clang and icc (and msvc)

Example:

------------------------------------
template <typename T>
class generic
{
public:
  generic() { T p; test(p); }
  generic(T *) {}
};

class Foo {};

void f(generic<Foo> const & = generic<Foo>());

int main() {}
------------------------------------

g++ -Wall -Wextra 8.3.6p5.cpp
8.3.6p5.cpp: In instantiation of 'generic<T>::generic() [with T = Foo]':
8.3.6p5.cpp:11:44:   required from here
8.3.6p5.cpp:5:20: error: 'test' was not declared in this scope

Reply via email to