Bug 15867 - -Wredundant-decls and explicit template specialization
Summary: -Wredundant-decls and explicit template specialization
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 4.7.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-08 05:16 UTC by Vladimir Prus
Modified: 2012-01-03 09:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95.3, 3.2.3, 3.3.4, 3.4.0, 4.0.0
Last reconfirmed: 2005-05-01 03:47:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Prus 2004-06-08 05:16:53 UTC
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.
Comment 1 Wolfgang Bangerth 2004-06-08 13:29:06 UTC
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. 
Comment 2 Paolo Carlini 2012-01-02 21:51:11 UTC
Seems doable.
Comment 3 paolo@gcc.gnu.org 2012-01-03 09:33:37 UTC
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
Comment 4 Paolo Carlini 2012-01-03 09:35:18 UTC
Fixed for 4.7.0.