Open Machiry opened 5 years ago
I came across the same issue, but with literal strings, not just variables.
This code will produce an error:
#include <string_checked.h>
int main(int argc, nt_array_ptr<char> argv checked[] : count(argc)) {
_Nt_array_ptr<char> foo = strdup("hello");
}
error output:
foo.c:8:23: error: initializing '_Nt_array_ptr<char>' with an expression of incompatible type 'char *'
_Nt_array_ptr<char> foo = strdup("hello");
^ ~~~~~~~~~~~~~~~
1 error generated.
But if you wrap the code in a CHECKED_SCOPE
then the error is resolved, i.e.:
#include <string_checked.h>
#include <stdchecked.h>
#pragma CHECKED_SCOPE ON
int main(int argc, nt_array_ptr<char> argv checked[] : count(argc)) {
_Nt_array_ptr<char> foo = strdup("hello");
}
#pragma CHECKED_SCOPE OFF
You can alternatively cast the return type of strdup()
to _Nt_array_ptr<char>
and that will also resolve the error, i.e.:
#include <string_checked.h>
int main() {
_Nt_array_ptr<char> foo = (_Nt_array_ptr<char>)strdup("hello");
}
This is a compiler bug. It's likely related to an oversight when handling of _Nt_array_ptr<char>.
The following code works as expected:
char *f(void) : itype(_Array_ptr<char>);
void g(void) {
array_ptr<char> src1 = f();
}
Problem:
The following program is supposed to compile file.
But we are getting the following error:
I think this is because of the improper handling of
itypes
for return values.