Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warnings in test programs #132

Open
carns opened this issue Apr 29, 2021 · 2 comments
Open

warnings in test programs #132

carns opened this issue Apr 29, 2021 · 2 comments

Comments

@carns
Copy link
Member

carns commented Apr 29, 2021

With gcc 10.2, on Ubuntu, I get the following warnings in the test programs:

../tests/margo-test-init-ext.c: In function ‘readfile’:
../tests/margo-test-init-ext.c:26:5: warning: ignoring return value of ‘fread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |     fread(string, 1, fsize, f);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~

../tests/unit-tests/helper-server.c: In function ‘HS_start’:
../tests/unit-tests/helper-server.c:37:13: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |             write(p[1], addr_size, sizeof(*addr_size));
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/unit-tests/helper-server.c:38:13: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |             write(p[1], addr, *addr_size);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/unit-tests/helper-server.c:53:13: warning: ignoring return value of ‘read’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |             read(p[0], addr_size, sizeof(*addr_size));
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/unit-tests/helper-server.c:54:13: warning: ignoring return value of ‘read’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |             read(p[0], addr, *addr_size);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

These are trivial, but part of why I opened an issue is that I'm curious about what CFLAGS make them appear. Counterintuitively, there are no warnings emitted on my laptop if I have -Wall set, but they do appear if my CFLAGS are empty at configure time.

@roblatham00
Copy link
Contributor

it's in the warning string: -Wunused-result

@roblatham00
Copy link
Contributor

fun discussion here https://stackoverflow.com/questions/7271939/warning-ignoring-return-value-of-scanf-declared-with-attribute-warn-unused-r -- it's an attribute on the stdio functions but one only sees the warning with -O2 optimizations. Perhaps it is only with that additional level of optimization that the compiler can track used/unused values?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants