Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2004-08-23 05:06:50

On Mon, Aug 23, 2004 at 10:30:54AM +0200, Markus Sch?pflin wrote:

> Hello,
> currently beforementioned test fails on tru64cxx65 with the following error
> message:
> cxx: Error: ../libs/algorithm/string/test/container_test.cpp, line 94: #434
> a
> reference of type "char *&" (not const-qualified) cannot be
> initialized with a value of type "char [4]"
> argument_test( ach1, "abc" );

Long answer:

The difference between Comeau and cxx is that Comeau (and also GCC)
instantiates the template with T = char[4], binding a reference to that
type. cxx does an array-to-pointer conversion and then instantiates the
template with that type, and so fails to bind a non-const ref to the
char* temporary.

You can see the type Comeau and GCC instantiate the template with by adding
"no_such_function(C);" into the body of argument_test(), as the
resulting diagnostics will include "[with T=char [4]]" or similar.

The standard says that template argument deduction of type T happens for
an expression of the type "T[integer-constant]" which covers the case of
"char[4]", see example in para 10 of [temp.deduct.type] which deals with
types composed of the simpler types.

It also says that if a template function argument has been determined by
template argument deduction, that argument cannot also have promotions,
standard conversions, or user-defined conversions applied. That wording
is from Stroustrup, the corresponding text in the standard is para 1
[temp.over] IIUC.
AFAICT array-to-pointer conversion should only happen on a template
parameter for a non-type parameter.

Short answer: I think tru64cxx65 is wrong.


> The underlying problem is illustrated by the following code snippet:
> ---%<---
> template< typename T >
> void argument_cv_test( const T& C, const string& strResult )
> {
> }
> template< typename T >
> void argument_test( T& C, const string& strResult )
> {
> }
> void foo()
> {
> char ach1[]="abc";
> argument_cv_test( ach1, "abc" ); // ok
> argument_test( ach1, "abc" ); // not ok
> }
> --->%---
> The line marked as not ok triggers the error. I tried to compile that code
> snippet with Comeau online and it succeeds. But I could not find a
> definitive answer in the C++ standard whether that code is legal or not.
> If it's legal, could anyone please provide me with a reference to the
> paragraph of the standard which applies here? I would need that to file a
> proper bug report to HP.
> TIA, Markus
> _______________________________________________
> Unsubscribe & other changes:

"The tools we use have a profound (and devious!) influence on our
 thinking habits, and, therefore, on our thinking abilities."
	- Edsger Dijkstra

Boost list run by bdawes at, gregod at, cpdaniel at, john at