When compiling template<class T, class charT> class validator { public: void operator()() {} }; template<> void validator<bool, char>::operator()(); int main() {} With g++-3.4 -Wredundant-decls red.cpp I get this output: red.cpp:9: warning: redundant redeclaration of `void validator<T, charT>::operator()() [with T = bool, charT = char]' in same scope red.cpp:5: warning: previous declaration of `void validator<T, charT>::operator()() [with T = bool, charT = char]' I think the warning is incorrect. I'm specializating the member function, not redeclaring it.
Confirmed. It has nothing to do with an operator function, though: ----------------- template <typename T> struct S { void foo() {} }; template<> void S<int>::foo(); ----------------- We get the same behavior from 2.95 through mainline: g/x> /home/bangerth/bin/gcc-3.5*/bin/c++ -Wredundant-decls -c x.cc x.cc:5: warning: redundant redeclaration of `void S<T>::foo() [with T = int]' in same scope x.cc:2: warning: previous declaration of `void S<T>::foo() [with T = int]' This warning is wrong, though. W.
Seems doable.
Author: paolo Date: Tue Jan 3 09:33:33 2012 New Revision: 182833 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182833 Log: /cp 2012-01-03 Paolo Carlini <paolo.carlini@oracle.com> PR c++/15867 * decl.c (duplicate_decls): With -Wredundant-decls don't warn for declaration followed by specialization. /testsuite 2012-01-03 Paolo Carlini <paolo.carlini@oracle.com> PR c++/15867 * g++.dg/warn/Wredundant-decls-spec.C: New. Added: trunk/gcc/testsuite/g++.dg/warn/Wredundant-decls-spec.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/testsuite/ChangeLog
Fixed for 4.7.0.