You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Travis Vitek <tv...@quovadx.com> on 2007/09/13 01:31:43 UTC

RE: svn commit: r573119 - /incubator/stdcxx/trunk/tests/regress/24.operations.stdcxx-234.cpp

 
This regression test fails to compile on more than one platform for
varying reasons.

    ..\..\..\..\tests\containers\t.cpp(9) : error C2785:
'iterator_traits<_Iterator>::difference_type
std::distance(_ForwardIterator,_ForwardIterator)' and 'int
distance(X,X)' have different return types
        c:\build\stdcxx\include\rw/_iterbase.h(341) : see declaration of
'std::distance'
        ..\..\..\..\tests\containers\t.cpp(9) : see declaration of
'distance'
    ..\..\..\..\tests\containers\t.cpp(9) : error C2244: 'std::distance'
: unable to match function definition to an existing declaration

It appears that MSVC doesn't like that you haven't provided the template
parameter types for the specialization of distance().

 
/amd/devco/vitek/stdcxx/trunk/tests/regress/24.operations.stdcxx-234.cpp
:38: error: specialization of `template<class _ForwardIterator> typename
std::iterator_traits::difference_type std::distance(_ForwardIterator,
_ForwardIterator)' in different namespace
  /amd/devco/vitek/stdcxx/trunk/include/rw/_iterbase.h:342: error:
from definition of `template<class _ForwardIterator> typename
std::iterator_traits::difference_type std::distance(_ForwardIterator,
_ForwardIterator)'
  gmake: *** [24.operations.stdcxx-234.o] Error 1

It looks like gcc doesn't like how you've put the distance()
specialization into namespace std. It appears that this is supposed to
be legal [14.7.3 p9], but gcc rejects the code.

I'm attaching a patch that I've tested on VC8 and gcc 3.4.6. It should
also compile on.


2007-09-12  Travis Vitek  <vi...@roguewave.com>

	* 24.operations.stdcxx-234.cpp: change to get regression
	test to correctly compile on gcc and msvc.

Index: 24.operations.stdcxx-234.cpp
===================================================================
--- 24.operations.stdcxx-234.cpp	(revision 573323)
+++ 24.operations.stdcxx-234.cpp	(working copy)
@@ -31,13 +31,18 @@
 
 struct X: std::iterator<std::random_access_iterator_tag, int> { };
 
+namespace std {
+
 // specialize the std::distance() function template of a user-defined
 // iterator type to verify that the signature of the primary template
 // is the same as the one of the specialization
 template <> std::iterator_traits<X>::difference_type
-std::distance (X, X) { return 0; }
+distance<X> (X, X) { return 0; }
 
+} // namespace std
+
 int main ()
 {
     return std::distance (X (), X ());
 }
+



>-----Original Message-----
>From: sebor@apache.org [mailto:sebor@apache.org] 
>Sent: Wednesday, September 05, 2007 5:30 PM
>To: stdcxx-commits@incubator.apache.org
>Subject: svn commit: r573119 - 
>/incubator/stdcxx/trunk/tests/regress/24.operations.stdcxx-234.cpp
>
>Author: sebor
>Date: Wed Sep  5 17:30:13 2007
>New Revision: 573119
>
>URL: http://svn.apache.org/viewvc?rev=573119&view=rev
>Log:
>2007-09-06  Martin Sebor  <se...@roguewave.com>
>
>	* 24.operations.stdcxx-234.cpp: Added a regression test 
>for STDCXX-234.
>
>

Re: svn commit: r573119 - /incubator/stdcxx/trunk/tests/regress/24.operations.stdcxx-234.cpp

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
> 
>> Martin Sebor wrote:
>>
>> Travis Vitek wrote:
>>>  
>>>
>>> It appears that MSVC doesn't like that you haven't provided 
>>> the template parameter types for the specialization of distance().
>> Looks like a compiler bug. We should report it to Microsoft.
>> If you don't have one yet, this might be a good opportunity
>> to set up an account with them and learn how to do it :)
>>
> 
> Done. http://tinyurl.com/2u7ave. [14.7.3 p10]

Good. Of course, they immediately closed it as not reproducible
in their internal version with no reference to an existing bug
report so we can only hope that they have a regression test for
it and/or that it doesn't regress between now and the final
release...

> 
>>> It looks like gcc doesn't like how you've put the distance()
>>> specialization into namespace std. It appears that this is 
>>> supposed to be legal [14.7.3 p9], but gcc rejects the code.
>> Yes, it's a gcc 3.2 bug. We reported it back in 2002:
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8266
>>
> 
> Well I was compiling with gcc 3.4.6, and your testcase is different from
> what we have here. I _believe_ that the gcc testcase you provided is
> explicitly instantiating the foo() template on int. That is very
> different from the problem I'm describing.
> 
> I don't really think this is a gcc bug [but it is likely to be a msvc
> bug]. From the 2003 version of the standard...

Are you saying you're disagreeing with me?! ;-)

You're right, I misremembered the problem. It's too bad that this
syntax is ill-formed for explicit specialization because the same
syntax is allowed for explicit instantiation:

   namespace N { template <class T> void foo (T) { } }
   template void N::foo (int);          // okay
   extern template void N::foo (int);   // okay (w/o the above)
   template <> void N::foo (long) { }   // error

Martin

> 
> [14.7.3 p2] An explicit specialization shall be declared in the
> namespace
> of which the template is a member, or, for member templates, [...] Such
> a
> declaration may also be a definition. If the declaration is not a
> definition, the specialization may be defined later (7.3.1.2).
> 
> [7.3.1.2 p2] Members (including explicit specializations of templates
> (14.7.3)) of a named namespace can be defined outside that namespace by
> explicit qualification (3.4.3.2) of the name being defined, provided
> that
> the entity being defined was already declared in the namespace and the
> declaration appears after the point of declaration in a namespace that
> encloses the declaratsion's namespace. [Example:
> 
>     namespace Q {
>         namespace V {
>             void f();
>         }
>         void V::f() { /*...*/ }  // OK
>         void V::g() { /*...*/ }  // error: g() is not yet a member of V
>         namespace V {
>             void g();
>         }
>     }
> 
>     namespace R {
>         void Q::V::g() { /*...*/ } // error: R doesn't enclose Q
>     }
> ]
> 
> Travis
> 


RE: svn commit: r573119 - /incubator/stdcxx/trunk/tests/regress/24.operations.stdcxx-234.cpp

Posted by Travis Vitek <tv...@quovadx.com>.
 

> Martin Sebor wrote:
>
>Travis Vitek wrote:
>>  
>> 
>> It appears that MSVC doesn't like that you haven't provided 
>> the template parameter types for the specialization of distance().
>
>Looks like a compiler bug. We should report it to Microsoft.
>If you don't have one yet, this might be a good opportunity
>to set up an account with them and learn how to do it :)
>

Done. http://tinyurl.com/2u7ave. [14.7.3 p10]

>
>> 
>> It looks like gcc doesn't like how you've put the distance()
>> specialization into namespace std. It appears that this is 
>> supposed to be legal [14.7.3 p9], but gcc rejects the code.
>
>Yes, it's a gcc 3.2 bug. We reported it back in 2002:
>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8266
>

Well I was compiling with gcc 3.4.6, and your testcase is different from
what we have here. I _believe_ that the gcc testcase you provided is
explicitly instantiating the foo() template on int. That is very
different from the problem I'm describing.

I don't really think this is a gcc bug [but it is likely to be a msvc
bug]. From the 2003 version of the standard...

[14.7.3 p2] An explicit specialization shall be declared in the
namespace
of which the template is a member, or, for member templates, [...] Such
a
declaration may also be a definition. If the declaration is not a
definition, the specialization may be defined later (7.3.1.2).

[7.3.1.2 p2] Members (including explicit specializations of templates
(14.7.3)) of a named namespace can be defined outside that namespace by
explicit qualification (3.4.3.2) of the name being defined, provided
that
the entity being defined was already declared in the namespace and the
declaration appears after the point of declaration in a namespace that
encloses the declaratsion's namespace. [Example:

    namespace Q {
        namespace V {
            void f();
        }
        void V::f() { /*...*/ }  // OK
        void V::g() { /*...*/ }  // error: g() is not yet a member of V
        namespace V {
            void g();
        }
    }

    namespace R {
        void Q::V::g() { /*...*/ } // error: R doesn't enclose Q
    }
]

Travis

Re: svn commit: r573119 - /incubator/stdcxx/trunk/tests/regress/24.operations.stdcxx-234.cpp

Posted by Martin Sebor <se...@roguewave.com>.
Travis Vitek wrote:
>  
> This regression test fails to compile on more than one platform for
> varying reasons.
> 
>     ..\..\..\..\tests\containers\t.cpp(9) : error C2785:
> 'iterator_traits<_Iterator>::difference_type
> std::distance(_ForwardIterator,_ForwardIterator)' and 'int
> distance(X,X)' have different return types
>         c:\build\stdcxx\include\rw/_iterbase.h(341) : see declaration of
> 'std::distance'
>         ..\..\..\..\tests\containers\t.cpp(9) : see declaration of
> 'distance'
>     ..\..\..\..\tests\containers\t.cpp(9) : error C2244: 'std::distance'
> : unable to match function definition to an existing declaration
> 
> It appears that MSVC doesn't like that you haven't provided the template
> parameter types for the specialization of distance().

Looks like a compiler bug. We should report it to Microsoft.
If you don't have one yet, this might be a good opportunity
to set up an account with them and learn how to do it :)

Here's the URL:
https://connect.microsoft.com/

> 
>  
> /amd/devco/vitek/stdcxx/trunk/tests/regress/24.operations.stdcxx-234.cpp
> :38: error: specialization of `template<class _ForwardIterator> typename
> std::iterator_traits::difference_type std::distance(_ForwardIterator,
> _ForwardIterator)' in different namespace
>   /amd/devco/vitek/stdcxx/trunk/include/rw/_iterbase.h:342: error:
> from definition of `template<class _ForwardIterator> typename
> std::iterator_traits::difference_type std::distance(_ForwardIterator,
> _ForwardIterator)'
>   gmake: *** [24.operations.stdcxx-234.o] Error 1
> 
> It looks like gcc doesn't like how you've put the distance()
> specialization into namespace std. It appears that this is supposed to
> be legal [14.7.3 p9], but gcc rejects the code.

Yes, it's a gcc 3.2 bug. We reported it back in 2002:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8266

> 
> I'm attaching a patch that I've tested on VC8 and gcc 3.4.6. It should
> also compile on.

Committed thus:
http://svn.apache.org/viewvc?rev=575132&view=rev

Thanks!
Martin