Skip to content

[tcling] Suppress -Wunused-result diagnostics in wrappers generated by TClingCallFunc#9244

Merged
jalopezg-git merged 3 commits intoroot-project:masterfrom
jalopezg-git:fix-issue-8622
Nov 7, 2021
Merged

[tcling] Suppress -Wunused-result diagnostics in wrappers generated by TClingCallFunc#9244
jalopezg-git merged 3 commits intoroot-project:masterfrom
jalopezg-git:fix-issue-8622

Conversation

@jalopezg-git
Copy link
Copy Markdown
Contributor

@jalopezg-git jalopezg-git commented Nov 4, 2021

This pull-request suppresses -Wunused-result diagnostics for wrapper functions generated by TClingCallFunc (see below).

A TClingCallFunc wrapper function might look as the excerpt below, where the function denoted by func may have been annotated as [[nodiscard]]. Note that if ret == nullptr the result of the call is unused.

extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret) {
   if (ret) {
      new (ret) (return_type) ((class_name*)obj)->func(args...);
   }
   else {
      ((class_name*)obj)->func(args...);
   }
}

In turn, this triggers warnings when used by cppyy/PyROOT, e.g.

>>> import ROOT
>>> v = ROOT.std.vector(int)()
>>> v.empty()
input_line_34:10:7: warning; ignoring return value of function declared with 'nodiscard' attribute
      [-Wunused-result]
      ((const vector<int>*)obj)->empty();
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
True
>>>

Changes or fixes:

  • Given the above situation, this commit supresses -Wunused-result diagnostics only for TClingCallFunc wrapper functions.

Checklist:

  • tested changes locally

This PR fixes #8622.

Sibling PR in roottest: root-project/roottest#791

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

Copy link
Copy Markdown
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for finding this out it !

@eguiraud
Copy link
Copy Markdown
Contributor

eguiraud commented Nov 4, 2021

Would changing

((class_name*)obj)->func(args...);

to

(void)((class_name*)obj)->func(args...);

also fix it? (I can't judge if that's a better or worse solution :) )

@pcanal
Copy link
Copy Markdown
Member

pcanal commented Nov 4, 2021

I think Enrico's solution might be slight better as it is a more local solution (and clarify the intent of the code).

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@jalopezg-git jalopezg-git changed the title [tcling] Ignore -Wunused-result diagnostics in wrappers generated by TClingCallFunc [tcling] Suppress -Wunused-result diagnostics in wrappers generated by TClingCallFunc Nov 4, 2021
@jalopezg-git
Copy link
Copy Markdown
Contributor Author

Would changing

((class_name*)obj)->func(args...);

to

(void)((class_name*)obj)->func(args...);

also fix it? (I can't judge if that's a better or worse solution :) )

Yes, of course. Changed! Thanks for the suggestion, @eguiraud!

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft23.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

Copy link
Copy Markdown
Member

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Warnings:

  • [2021-11-04T18:40:03.077Z] ghprbPullLongDescription=This pull-request suppresses -Wunused-result diagnostics for wrapper functions generated by TClingCallFunc (see below).\r\n\r\nA TClingCallFunc wrapper function might look as the excerpt below, where the function denoted by func may have been annotated as [[nodiscard]]. Note that if ret == nullptr the result of the call is unused.\r\nc++\r\nextern \"C\" void __cf_0(void* obj, int nargs, void** args, void* ret) {\r\n if (ret) {\r\n new (ret) (return_type) ((class_name*)obj)-&gt;func(args...);\r\n }\r\n else {\r\n ((class_name*)obj)-&gt;func(args...);\r\n }\r\n}\r\n\r\n\r\nIn turn, this triggers warnings when used by cppyy/PyROOT, e.g.\r\npython\r\n&gt;&gt;&gt; import ROOT\r\n&gt;&gt;&gt; v = ROOT.std.vector(int)()\r\n&gt;&gt;&gt; v.empty()\r\ninput_line_34:10:7: warning: ignoring return value of function declared with 'nodiscard' attribute\r\n [-Wunused-result]\r\n ((const vector&lt;int&gt;*)obj)-&gt;empty();\r\n ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\nTrue\r\n&gt;&gt;&gt;\r\n\r\n\r\n## Changes or fixes:\r\n- Given the above situation, this commit supresses -Wunused-result diagnostics only for TClingCallFunc wrapper functions.\r\n\r\n## Checklist:\r\n- [X] tested changes locally\r\n\r\nThis PR fixes PyROOT triggers a warning about [[nodiscard]] vector::empty with GCC11 #8622.

Failing tests:

…y TClingCallFunc

A TClingCallFunc wrapper function might look as the excerpt below, where the
function denoted by `func` may have been annotated as `[[nodiscard]]`. Note that
if `ret == nullptr` the result of the call is unused.
```
extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret) {
   if (ret) {
      new (ret) (return_type) ((class_name*)obj)->func(args...);
   }
   else {
      ((class_name*)obj)->func(args...);
   }
}
```

In turn, this triggers warnings when used by cppyy/PyROOT, e.g.
```
>>> import ROOT
>>> v = ROOT.std.vector(int)()
>>> v.empty()
input_line_34:10:7: warning: ignoring return value of function declared with 'nodiscard' attribute
      [-Wunused-result]
      ((const vector<int>*)obj)->empty();
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
True
>>>
```

Given the above, the second call expression will be casted to `void`.

Closes issue root-project#8622.
@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
Running on sft-ubuntu-1604-1.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-11-05T19:09:23.977Z] FAILED: /usr/bin/ccache /usr/bin/c++ -I/mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/../res -I/mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/../../clingutils/res -I/mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/../../foundation/res -I/mnt/build/workspace/root-pullrequests-build/root/interpreter/cling/include -Iginclude -I/mnt/build/workspace/root-pullrequests-build/root/core/base/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/foundation/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/cont/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/gui/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/meta/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/clib/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/rint/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/zip/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/thread/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/textinput/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/clingutils/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/base/v7/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/foundation/v7/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/unix/inc -Icore/metacling/test -I/mnt/build/workspace/root-pullrequests-build/root/test/unit_testing_support -isystem googletest-prefix/src/googletest/googletest/include -isystem googletest-prefix/src/googletest/googlemock/include -fdiagnostics-color=always -std=c++14 -pipe -Wshadow -Wall -W -Woverloaded-virtual -fsigned-char -pthread -O3 -std=c++14 -MD -MT core/metacling/test/CMakeFiles/TClingTest.dir/TClingCallFuncTests.cxx.o -MF core/metacling/test/CMakeFiles/TClingTest.dir/TClingCallFuncTests.cxx.o.d -o core/metacling/test/CMakeFiles/TClingTest.dir/TClingCallFuncTests.cxx.o -c /mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx
  • [2021-11-05T19:09:23.977Z] /mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:296:23: error: missing template arguments before ‘RAII’
  • [2021-11-05T19:09:23.977Z] /mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:300:8: error: expected primary-expression before ‘)’ token

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-11-05T19:10:04.755Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:296:23: error: missing template arguments before ‘RAII’
  • [2021-11-05T19:10:04.755Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:300:8: error: expected primary-expression before ‘)’ token

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu16/nortcxxmod.
Running on sft-ubuntu-1604-1.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-11-05T19:14:12.102Z] FAILED: /usr/bin/ccache /usr/bin/c++ -I/mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/../res -I/mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/../../clingutils/res -I/mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/../../foundation/res -I/mnt/build/workspace/root-pullrequests-build/root/interpreter/cling/include -Iginclude -I/mnt/build/workspace/root-pullrequests-build/root/core/base/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/foundation/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/cont/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/gui/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/meta/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/clib/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/rint/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/zip/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/thread/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/textinput/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/clingutils/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/base/v7/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/foundation/v7/inc -I/mnt/build/workspace/root-pullrequests-build/root/core/unix/inc -Icore/metacling/test -I/mnt/build/workspace/root-pullrequests-build/root/test/unit_testing_support -isystem googletest-prefix/src/googletest/googletest/include -isystem googletest-prefix/src/googletest/googlemock/include -fdiagnostics-color=always -std=c++14 -pipe -Wshadow -Wall -W -Woverloaded-virtual -fsigned-char -pthread -O3 -std=c++14 -MD -MT core/metacling/test/CMakeFiles/TClingTest.dir/TClingCallFuncTests.cxx.o -MF core/metacling/test/CMakeFiles/TClingTest.dir/TClingCallFuncTests.cxx.o.d -o core/metacling/test/CMakeFiles/TClingTest.dir/TClingCallFuncTests.cxx.o -c /mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx
  • [2021-11-05T19:14:12.102Z] /mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:296:23: error: missing template arguments before ‘RAII’
  • [2021-11-05T19:14:12.102Z] /mnt/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:300:8: error: expected primary-expression before ‘)’ token

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-ubuntu2004/soversion.
Running on root-ubuntu-2004-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-11-05T19:14:07.595Z] FAILED: core/metacling/test/CMakeFiles/TClingTest.dir/TClingCallFuncTests.cxx.o
  • [2021-11-05T19:14:07.853Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:296:23: error: missing template arguments before ‘RAII’
  • [2021-11-05T19:14:07.853Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:300:8: error: expected primary-expression before ‘)’ token

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-debian10-i386/cxx14.
Running on pcepsft10.dyndns.cern.ch:/build/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-11-05T19:15:00.663Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:296:23: error: missing template arguments before ‘RAII’
  • [2021-11-05T19:15:00.663Z] /home/sftnight/build/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:300:8: error: expected primary-expression before ‘)’ token

@phsft-bot
Copy link
Copy Markdown

Build failed on ROOT-performance-centos8-multicore/default.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

Errors:

  • [2021-11-05T19:16:38.990Z] /data/sftnight/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:296:23: error: missing template arguments before ‘RAII’
  • [2021-11-05T19:16:38.990Z] /data/sftnight/workspace/root-pullrequests-build/root/core/metacling/test/TClingCallFuncTests.cxx:300:8: error: expected primary-expression before ‘)’ token

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on windows10/cxx14.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Errors:

  • [2021-11-07T18:58:03.050Z] CMake Error at C:/build/workspace/root-pullrequests-build/rootspi/jenkins/root-build.cmake:1095 (message):

@phsft-bot
Copy link
Copy Markdown

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-ubuntu16/nortcxxmod, ROOT-ubuntu2004/soversion, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@phsft-bot
Copy link
Copy Markdown

Build failed on mac11.0/cxx17.
Running on macphsft20.dyndns.cern.ch:/Users/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

Copy link
Copy Markdown
Member

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

Lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PyROOT triggers a warning about [[nodiscard]] vector::empty with GCC11

6 participants