chapel
chapel copied to clipboard
[Bug?]: Inconsistency with c_array documentation and c_array behavior w.r.t. coercion to c_ptr
Summary of Problem
Description:
I'm not sure how much of this is user error on my part, but I'm having difficulty using a c_array as though it was a c_ptr for the purpose of calling string.createCopyingBuffer
(which accepts a c_ptr or a c_ptrConst).
The documentation for c_array says:
A variable of type c_array can coerce to a c_ptr with the same element type. In that event, the pointer will be equivalent to c_ptrTo(array[0]).
And the documentation for coercions says:
An implicit conversion for a function call - also called a coercion - occurs when the actual argument of a function call is converted to the type of the corresponding formal argument, if the formal’s intent is param, in, const in, const, or the default intent.
Given that the argument for string.createCopyingBuffer
uses the default intent, my expectation based on these two paragraphs is that I should be able to pass a c_array
to that function without an explicit cast. However, when I try to do so, I get an unresolved call error. I think this means that either the documentation or the compiler needs to be updated.
Is this a blocking issue with no known work-arounds? No. I encountered this while writing an example for another user (so nothing in work I was doing myself) and it looks like an explicit cast may be okay (though I'm having other difficulties that could also just be user error on my part, so I can't verify that the cast works at execution time until I figure those out).
Steps to Reproduce
Source Code:
// <some valid code to create a c_array named cArr>
var str = string.createCopyingBuffer(cArr);
Compile command:
chpl foo.chpl
Execution command: N/A
Associated Future Test(s): TBD
Configuration Information
- Output of
chpl --version
: 2.1.0 pre-release - Output of
$CHPL_HOME/util/printchplenv --anonymize
: Any, this is a compiler error - Back-end compiler and version, e.g.
gcc --version
orclang --version
: Any, this is a compiler error - (For Cray systems only) Output of
module list
: N/A