This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-01-15


24. Errors in examples in 14.7.3

Section: 13.9.4  [temp.expl.spec]     Status: TC1     Submitter: unknown     Date: unknown

Problem Description: At least four of the examples in 13.9.4 [temp.expl.spec] have errors.

Proposed Resolution (10/99):

1. Change the example in paragraph 8 from:

[Example:
    // file #1 
    #include <vector>
    // Primary class template vector
    export template<class T> void f(t) {
        vector<T> vec;         // should match the specialization
        /* ... */
    }

    // file #2 
    #include <vector>
    class B { };
    // Explicit specialization of vector for vector<B>
    template<class T> class vector<B> { /* ... */ }
    template<class T> void f(T);
    void g(B b) {
        f(b);                   // ill formed: 
                                // f<B> should refer to vector<B>, but the 
                                // specialization was not declared with the 
                                // definition of f in file #1 
    }
—end example]
to:
[Example:
    // file #1 
    #include <vector>
    // Primary class template vector
    export template<class T> void f(T) {
        std::vector<T> vec;     // should match the specialization 
        /* ... */
    };

    // file #2 
    #include <vector>
    class B { };
    // Explicit specialization of vector for vector<B>
    namespace std {
        template<> class vector<B> { /* ... */ };
    }
    template<class T> void f(T);
    void g(B b) {
        f(b);                   // ill formed: 
                                // f<B> should refer to vector<B>, but the 
                                // specialization was not declared with the 
                                // definition of f in file #1 
    }
—end example]

2. The example in paragraph 16 as it appears in the IS:

[Example:
    template<class T> struct A {
        void f(T);
        template<class X> void g(T, X);
        void h(T) { }
    };

    // specialization 
    template<> void A<int>::f(int);

    // out of class member template definition 
    template<class T> template<class X> void A<T>::g(T,X) { }

    // member template partial specialization 
    template<> template<class X> void A<int>::g(int, X);

    // member template specialization 
    template<> template<>
        void A<int>::g(int, char);        // X deduced as char
    template<> template<>
        void A<int>::g<char>(int, char);  // X specified as char

    // member specialization even if defined in class definition 
    template<> void A<int>::h(int) { }
end example]
The word 'partial' in the third comment in the example should be removed because this example does not illustrate partial specialization. Also, the two specializations of template<> template<> void A<int>::g(int, char); violate 13.9 [temp.spec] , paragraph 5, which reads:
No program shall explicitly instantiate any template more than once, both explicitly instantiate and explicitly specialize a template, or specialize a template more than once for a given set of template-arguments. An implementation is not required to diagnose a violation of this rule.
Proposed resolution (10/99):
[Example:
    template<class T> struct A {
        void f(T);
        template<class X1> void g1(T, X1);
        template<class X2> void g2(T, X2);
        void h(T) { }
    };

    // specialization 
    template<> void A<int>::f(int);

    // out of class member template definition 
    template<class T> template<class X1> void A<T>::g1(T,X1) { }

    // member template specialization 
    template<> template<class X1> void A<int>::g1(int, X1);

    // member template specialization 
    template<> template<>
        void A<int>::g1(int, char);        // X1 deduced as char
    template<> template<>
        void A<int>::g2<char>(int, char);  // X2 specified as char

    // member specialization even if defined in class definition 
    template<> void A<int>::h(int) { }
end example]

3. Remove the spurious semicolon (or the curly brackets) from the end of the last line in the example in paragraph 17. This is the example as it appears in the IS:

[Example:
    template<class T1> class A {
        template<class T2> class B {
            void mf();
        };
    };
    template<> template<> A<int>::B<double> { };
    template<> template<> void A<char>::B<char>::mf() {};
end example]
Proposed resolution (10/99):
[Example:
    template<class T1> class A {
        template<class T2> class B {
            void mf();
        };
    };
    template<> template<> A<int>::B<double>;
    template<> template<> void A<char>::B<char>::mf();
end example]

Note (Steve Adamczyk, March 2002): that's still incorrect. The missing "class" was added editorially when TC1 was prepared.

4. Remove spurious semicolons (or curly brackets) from the specializations of mf1 and mf2 in the example in paragraph 18. This is the text of the example as it appears in the IS:

[Example:
    template<class T1> class A {
        template<class T2> class B {
            template<class T3> void mf1(T3);
            void mf2();
        };
    };
    template<> template<class X>
        class A<int>::B { };
    template<> template<> template<class T>
        void A<int>::B<double>::mf1(T t) { };
    template<class Y> template<>
        void A<Y>::B<double>::mf2() { }; // ill-formed; B<double> is specialized but 
                                         // its enclosing class template A is not 
end example]
Proposed resolution (10/99):
[Example:
    template<class T1> class A {
        template<class T2> class B {
            template<class T3> void mf1(T3);
            void mf2();
        };
    };
    template<> template<class X>
        class A<int>::B { };
    template<> template<> template<class T>
        void A<int>::B<double>::mf1(T t) { }
    template<class Y> template<>
        void A<Y>::B<double>::mf2() { } // ill-formed; B<double> is specialized but 
                                         // its enclosing class template A is not 
end example]

Note (Steve Adamczyk, March 2002): that's still incorrect. See issue 336.