[clang++] GCC/clang difference

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[clang++] GCC/clang difference

Nate Knight
I have a question regarding the following code:

template<typename T>
struct A
{
    const static int type;
};

template<typename T>
struct B
{
    typedef A<T> C;
};

typedef B<int>::C D;
//const int D::type = 2;
template<> const int D::type = 2;

int main()
{
    B<int> b;
}

gcc 4.5 and 4.6(beta) require the "template<>" in front of "const in D::type = 2" with the error "error: specializing member 'A<int>::type' requires 'template<>' syntax"

gcc 4.3 and 4.4 give the error "too few template-parameter-lists"

clang++ (trunk 121734) gives an error if the "template<>" is present.

Can someone point me to the relevant section of the standard defining the required behavior here?  I'm trying to determine where to submit an issue report.

Thanks
Nate Knight
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [clang++] GCC/clang difference

Alistair Lynn
Hi Nate-

This would appear to be covered in ยง14.7.3 (temp.expl.spec) which says that GCC is right.

Alistair

On 20 Dec 2010, at 21:54, Nate Knight wrote:

> I have a question regarding the following code:
>
> template<typename T>
> struct A
> {
>    const static int type;
> };
>
> template<typename T>
> struct B
> {
>    typedef A<T> C;
> };
>
> typedef B<int>::C D;
> //const int D::type = 2;
> template<> const int D::type = 2;
>
> int main()
> {
>    B<int> b;
> }
>
> gcc 4.5 and 4.6(beta) require the "template<>" in front of "const in D::type = 2" with the error "error: specializing member 'A<int>::type' requires 'template<>' syntax"
>
> gcc 4.3 and 4.4 give the error "too few template-parameter-lists"
>
> clang++ (trunk 121734) gives an error if the "template<>" is present.
>
> Can someone point me to the relevant section of the standard defining the required behavior here?  I'm trying to determine where to submit an issue report.
>
> Thanks
> Nate Knight
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [clang++] GCC/clang difference

Douglas Gregor
In reply to this post by Nate Knight

On Dec 20, 2010, at 1:54 PM, Nate Knight wrote:

> I have a question regarding the following code:
>
> template<typename T>
> struct A
> {
>    const static int type;
> };
>
> template<typename T>
> struct B
> {
>    typedef A<T> C;
> };
>
> typedef B<int>::C D;
> //const int D::type = 2;
> template<> const int D::type = 2;
>
> int main()
> {
>    B<int> b;
> }
>
> gcc 4.5 and 4.6(beta) require the "template<>" in front of "const in D::type = 2" with the error "error: specializing member 'A<int>::type' requires 'template<>' syntax"
>
> gcc 4.3 and 4.4 give the error "too few template-parameter-lists"
>
> clang++ (trunk 121734) gives an error if the "template<>" is present.
>
> Can someone point me to the relevant section of the standard defining the required behavior here?  I'm trying to determine where to submit an issue report.

This area of the standard is a complete mess. Check out

        http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#529

which deals with the same issue and has various pointers into the (contradictory) passages in the working paper. Clang was meant to follow the proposed resolution of this core issue.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev