Bug 57314 (CWG1635)

Summary: [Core/1635] default template arguments for member template functions of class templates are instantiated before allowed
Product: gcc Reporter: Florian J. Weber <oss>
Component: c++Assignee: Marek Polacek <mpolacek>
Status: ASSIGNED ---    
Severity: normal CC: daniel.kruegler, mpolacek, webrown.cpp
Priority: P3    
Version: 4.8.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2013-05-18 00:00:00
Bug Depends on:    
Bug Blocks: 94404, 98939    

Description Florian J. Weber 2013-05-17 15:10:03 UTC
GCC rejects the following code:

#include <type_traits>

template<bool bar> struct foo{
	template<typename T, typename = typename std::enable_if<bar>::type>
	void fun(T){}
};

int main(){
	foo<false> var{};
}

The error claims: “error: no type named 'type' in 'struct std::enable_if<false, void>”. Which is certainly true but according to my reading of the standard perfectly OK, because the default-arguments of templates must not be instantiated before usage:

Section 14.7.1:
“...The implicit instantiation of a class template specialization causes the implicit instantiation of the declarations, but not of the definitions or default arguments, of the class member functions, member classes, scoped member enumerations, static data members and member templates;...“
Comment 1 Daniel Krügler 2013-05-18 14:39:49 UTC
The standard does not clearly say that. Note that "default arguments" doesn't naturally extend to default *template* arguments. There exists a core language issue in regard to this kind of example,

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1635
Comment 2 Paolo Carlini 2013-05-18 18:26:10 UTC
Thanks Daniel. Let's suspend this for now.
Comment 3 Marek Polacek 2021-07-08 17:02:47 UTC
I think this is resolved by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html -- in C++23, template default arguments are a complete-class context.  Will try to implement this in GCC 12.