Skip to content

Conversation

am11
Copy link
Member

@am11 am11 commented Jun 15, 2024

https://dev.azure.com/dnceng-public/public/_build/results?buildId=708804&view=logs&jobId=a3b522d2-1fcb-58aa-d1da-345566122d64&j=a3b522d2-1fcb-58aa-d1da-345566122d64&t=28177cd9-7046-57c0-17a4-2d126beee140

/__w/1/s/build.sh -ci -arch arm64 -os linux -cross -s clr.paltests+clr.paltestlist      
...
  [ 70%] Building CXX object pal/tests/palsuite/CMakeFiles/paltests.dir/file_io/ReadFile/test3/ReadFile.cpp.o
  /__w/1/s/src/coreclr/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.cpp:132:29: error: non-constant-expression cannot be narrowed from type 'size_t' (aka 'unsigned long') to 'DWORD' (aka 'unsigned int') in initializer list [-Wc++11-narrowing]
    132 |                             strlen(szStringTest),
        |                             ^~~~~~~~~~~~~~~~~~~~
  /__w/1/s/src/coreclr/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.cpp:132:29: note: insert an explicit cast to silence this issue
    132 |                             strlen(szStringTest),
        |                             ^~~~~~~~~~~~~~~~~~~~
        |                             static_cast<DWORD>( )
  /__w/1/s/src/coreclr/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.cpp:133:29: error: non-constant-expression cannot be narrowed from type 'long' to 'DWORD' (aka 'unsigned int') in initializer list [-Wc++11-narrowing]
    133 |                             pageSize
        |                             ^~~~~~~~
  /__w/1/s/src/coreclr/pal/tests/palsuite/file_io/ReadFile/test2/ReadFile.cpp:133:29: note: insert an explicit cast to silence this issue
    133 |                             pageSize
        |                             ^~~~~~~~
        |                             static_cast<DWORD>( )
  [ 70%] Building CXX object pal/tests/palsuite/CMakeFiles/paltests.dir/file_io/ReadFile/test4/readfile.cpp.o
  2 errors generated.

@ghost ghost added the area-PAL-coreclr label Jun 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 15, 2024
PALTEST(file_io_WriteFile_test2_paltest_writefile_test2, "file_io/WriteFile/test2/paltest_writefile_test2")
{
const char * testString = "The quick fox jumped over the lazy dog's back.";
const int testStringLen = strlen(testString);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this implicit size_t -> int cast be made explicit as well? It is interesting that the compiler is not complaining about this strlen("constant string"), but it is complaining about the other strlen("constant string").

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declaring it as DWORD also works without the explicit cast.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not depend on it. In general, compilers complain about any implicit narrowing these days.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-PAL-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants