[LLVMbugs] [Bug 8708] New: Clang rejects a number of explicit specializations

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 30 07:29:05 PST 2010


http://llvm.org/bugs/show_bug.cgi?id=8708

           Summary: Clang rejects a number of explicit specializations
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: schaub-johannes at web.de
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


I've tried to read through n3126's 14.7.3 explicit specialization subsection
and with the help of the GCC and Comeau-Online compilers came up with these
tests:

--------------------------------

template<typename T> struct A { 
  template<typename U> struct B {
    // #2
    void f();     
  }; 
};  

// #A specialize the member template for 
// implicit instantiation of A<int>,
// leaving the member template "unspecialized"
// (14.7.3/16). Specialization uses the syntax
// for explicit specialization (14.7.3/14)
template<> template<typename U> 
struct A<int>::B {
  // #1
  void g();
};  

// #1 define its function g. There is an enclosing
// class template, so we write template<> for each 
// specialized template (14.7.3/15).
template<> template<typename U>
void A<int>::B<U>::g() { }

// #2 define the unspecialized member template's
// f
template<typename T> template<typename U>
void A<T>::B<U>::f() { }


// specialize the member template again, now
// specializing the member too. This specializes
// #A
template<> template<>
struct A<int>::B<int> { 
  // #3
  void h();
};

// defines #3. There is no enclosing class template, so
// we write no "template<>".
void A<int>::B<int>::h() { }

int main() { 
  // calls #1
  A<int>::B<float> a; a.g(); 

  // calls #2
  A<float>::B<int> b; b.f();

  // calls #3
  A<int>::B<int> c; c.h();
}

-----------------------------

Clang gives the following diagnostics:

main1.cpp:23:20: error: specialization of member 'A<int>::B::g' does not
specialize an instantiated member
void A<int>::B<U>::g() { }
                   ^
main1.cpp:16:8: note: attempt to specialize declaration here                    
  void g();
       ^
main1.cpp:42:6: error: template specialization requires 'template<>'            
void A<int>::B<int>::h() { }
     ^~~~~~~~~~~~~~~~
template<>                                                                      
main1.cpp:42:22: error: specialization of member 'A<int>::B<int>::h' does not
specialize an instantiated member                                       
void A<int>::B<int>::h() { }
                     ^
main1.cpp:37:8: note: attempt to specialize declaration here                    
  void h();
       ^
main1.cpp:52:23: error: call to member function 'h' is ambiguous                
  A<int>::B<int> c; c.h();
                    ~~^
main1.cpp:37:8: note: candidate function                                        
  void h();
       ^
main1.cpp:42:22: note: candidate function                                       
void A<int>::B<int>::h() { }
                     ^
4 errors generated.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list