Bug 57314 (CWG1635) - [Core/1635] default template arguments for member template functions of class templates are instantiated before allowed
Summary: [Core/1635] default template arguments for member template functions of class...
Status: ASSIGNED
Alias: CWG1635
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks: c++-core-issues P1787R6
  Show dependency treegraph
 
Reported: 2013-05-17 15:10 UTC by Florian J. Weber
Modified: 2021-12-03 05:16 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-05-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.