[Bug c++/80771] New: GCC ignores default template argument declaration in the template definition
devgs at ukr dot net
gcc-bugzilla@gcc.gnu.org
Tue May 16 06:50:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80771
Bug ID: 80771
Summary: GCC ignores default template argument declaration in
the template definition
Product: gcc
Version: 7.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: devgs at ukr dot net
Target Milestone: ---
Compiled with: std=c++11
Affected versions: 4.8 - 7.1
#include <type_traits>
struct Foo
{ };
// This is a template function declaration, where second template argument
declared without a default
template <typename T, typename>
void foo(const Foo & foo, T t);
// This is a template function definition; second template argument now has a
default declared
template <typename T, typename = typename std::enable_if<1>::type>
void foo(const Foo & foo, T t)
{
}
int main(int argc, char ** argv)
{
foo(Foo{}, 1);
return 0;
}
GCC should merge default arguments, but it plainly ignores default argument in
the definition.
Standard [C++11 14.1 p10] says:
The set of default template-arguments available for use with a template
declaration or definition is obtained by merging the default arguments from the
definition (if in scope) and all declarations in scope in the same way default
function arguments are (8.3.6).
I could not find any other compiler that struggles with this piece of code,
except for GCC. And I tested a lot of them.
More information about the Gcc-bugs
mailing list