[Bug c++/54485] New: g++ should diagnose default arguments in out-of-line definitions for template class member functions
dnovillo at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Sep 4 21:27:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54485
Bug #: 54485
Summary: g++ should diagnose default arguments in out-of-line
definitions for template class member functions
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: dnovillo@gcc.gnu.org
CC: jason@gcc.gnu.org
In PR 54484, bootstraps were broken with clang++. The template class vec_t had
a member function with default arguments, but the default values were specified
in the function definition, instead of its declaration.
According to 8.3.6, that's incorrect: "Default arguments for a member function
of a class template shall be specified on the initial declaration of the member
function within the class template."
$ cat a.cc
template<typename T>
class K
{
int fn(int, int);
};
template<typename T>
int K<T>::fn (int a, int b = 3)
{
return a - b;
}
$ g++ -c a.cc
$ clang++ -c a.cc
a.cc:8:26: error: default arguments cannot be added to an out-of-line
definition of a member of a class template
int K<T>::fn (int a, int b = 3)
^ ~
1 error generated.
$ g++ --version
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.This is free software; see the
source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ clang++ --version
Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM
3.0)Target: x86_64-pc-linux-gnu
Thread model: posix
More information about the Gcc-bugs
mailing list