Fix warn_unused_result error in parquet test - #11026
Conversation
Codecov Report
@@ Coverage Diff @@
## branch-22.08 #11026 +/- ##
===============================================
Coverage ? 86.34%
===============================================
Files ? 144
Lines ? 22710
Branches ? 0
===============================================
Hits ? 19608
Misses ? 3102
Partials ? 0 Continue to review full report at Codecov.
|
| int fd = open(filepath.c_str(), O_RDONLY); | ||
| unsigned char buf[1024]; | ||
| read(fd, buf, sizeof(buf)); | ||
| (void)!read(fd, buf, sizeof(buf)); |
There was a problem hiding this comment.
How about [[maybe_unused]]?
There was a problem hiding this comment.
I think it is better to use [[maybe_unused]] instead of the old casting style, if it works.
There was a problem hiding this comment.
Should we verify the number of bytes read actually match what we expected? Instead of trying to sidestep the return value, why don't we actually use it?
There was a problem hiding this comment.
First, I tried [[maybe_unused]]. It didn't work.
cppreference says, This attribute can appear in the declaration of the following entities
So, it can be used only in declaration.
|
Thanks for fixing this. I'm thinking if we should replace the c-style system functions (e.g. |
| int fd = open(filepath.c_str(), O_RDONLY); | ||
| unsigned char buf[1024]; | ||
| read(fd, buf, sizeof(buf)); | ||
| (void)!read(fd, buf, sizeof(buf)); |
There was a problem hiding this comment.
I think it is better to use [[maybe_unused]] instead of the old casting style, if it works.
| int fd = open(filepath.c_str(), O_RDONLY); | ||
| unsigned char buf[1024]; | ||
| read(fd, buf, sizeof(buf)); | ||
| (void)!read(fd, buf, sizeof(buf)); |
There was a problem hiding this comment.
Should we verify the number of bytes read actually match what we expected? Instead of trying to sidestep the return value, why don't we actually use it?
| int fd = open(filepath.c_str(), O_RDONLY); | ||
| unsigned char buf[1024]; | ||
| read(fd, buf, sizeof(buf)); | ||
| (void)!read(fd, buf, sizeof(buf)); |
There was a problem hiding this comment.
| (void)!read(fd, buf, sizeof(buf)); | |
| size_t read_bytes = read(fd, buf, sizeof(buf)); | |
| EXPECT_EQ(read_bytes, sizeof(buf)); |
There was a problem hiding this comment.
It should read 1024 bytes unless the file is shorter or there is an error. This is why read returns the number of bytes actually read so you don't interpret garbage as real data.
There was a problem hiding this comment.
No, read_bytes is the actual size of read file, while sizeof(buff) is 1024. Do we know the file size beforehand?
There was a problem hiding this comment.
It should read 1024 bytes unless the file is shorter or there is an error.
Do we know the file size is >1024?
There was a problem hiding this comment.
Ah I see, file size should be bigger. But this is error-prone since we may change the file size generated above at any time.
There was a problem hiding this comment.
I agree that this logic could be made cleaner with c++ streams but for now, I don't see the test breaking on its own. Unless, of course, if the read fails altogether for some reason. @etseidl (author) can confirm.
Sorry, coming late to the game...I have changes to this test pending in a separate branch. PR will be coming as soon as I get work approval. I've completely reworked this test to use the cudf::io::datasource interface with the CompactProtocolReader.
Sorry for the trouble!
There was a problem hiding this comment.
@hyperbolic2346 @PointKernel I can cherry-pick out the changes for that test pretty easily. Should I do a smaller PR to fix this (hopefully) for good?
There was a problem hiding this comment.
If it is coming in 22.08, I wouldn't bother to pull it out.
There was a problem hiding this comment.
I am using c++ (Ubuntu 9.4.0-1ubuntu1~18.04) 9.4.0 in my local machine
I cannot replicate in godbolt. But can replicate same error in my local machine compilation
g++ -fdiagnostics-color=always -Wno-deprecated-declarations -O3 -DNDEBUG -fPIE -Wall -Werror -Wno-unknown-pragmas -Wno-error=deprecated-declarations -Wno-deprecated-declarations -pthread -std=gnu++17 test.cpp
#include <string>
#include <unistd.h>
#include <fcntl.h>
int main() {
std::string filepath = "CheckPageRows.parquet";
int fd = open(filepath.c_str(), O_RDONLY);
unsigned char buf[1024];
read(fd, buf, sizeof(buf));
return 0;
}test.cpp: In function ‘int main()’:
test.cpp:9:10: error: ignoring return value of ‘ssize_t read(int, void*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
9 | read(fd, buf, sizeof(buf));
| ~~~~^~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
same error with (void). Only with (void)! no errors.
There was a problem hiding this comment.
(base) yunsongw@yunsongw-dt:~/Work$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
(base) yunsongw@yunsongw-dt:~/Work$ g++ -Werror -O toto.cxx
toto.cxx: In function ‘int main()’:
toto.cxx:9:10: error: ignoring return value of ‘ssize_t read(int, void*, size_t)’, declared with attribute warn_unused_result [-Werror=unused-result]
9 | read(fd, buf, sizeof(buf));
| ~~~~^~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors-Werror -O is the minimum to replicate the error on my local system but I cannot reproduce the same error with any of the godbolt compiler versions (https://godbolt.org/z/f5aTzM7fx).
I would file an issue to track that and leave this PR as a quick fix. I assume that was your suggestion here, but I wanted to be sure it was spelled out. I don't want to burden @karthikeyann with that when this would be a better situation than we have now and it is ready to go. |
Works for me. Thanks for doing this! Edits: Didn't pay enough attention to Mike's comment. Thought you had opened the issue already. |
Mike said it was okay to leave this as a quick fix in a comment.
|
I dismissed the requests for changes and I'm going to merge this small fix. I will ask for forgiveness instead of permission on this one, if that's alright. It's blocking me and it has multiple approvals (both ✔️ and verbal support in comments). We have an open issue #11038 to track further improvements and planned changes in a future PR from @etseidl. |
|
@gpucibot merge |
|
But what about that exclamation point? Is |
|
@davidwendt I think the links in this thread should help answer your question about |
The ! is negating the return and then throwing it away. This makes the compiler happy because you technically used the return value. |
|
So why not just |
Fix
error: ignoring return value of declared with attribute warn_unused_resultin cpp/tests/io/parquet_test.cpp