-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Use pragmas to disable unused variable warnings in generated C++ #1422
base: master
Are you sure you want to change the base?
Conversation
I should note another option is to generate all our variable declarations with |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1422 +/- ##
==========================================
- Coverage 89.82% 89.79% -0.04%
==========================================
Files 63 63
Lines 10598 10594 -4
==========================================
- Hits 9520 9513 -7
- Misses 1078 1081 +3
|
Would this be controllable by a flag/option? CRAN rejects packages if the source has pragmas which suppress warnings |
Of course they do 🙃 Do they just do a string search, or if we put it inside the pre-existing |
Nope, they run the check on the package source after the
Yeah just a string-search/regex, it doesn't matter if you've |
But also not a blocker, since it's trivial to add a find-and-replace for the pragma to the rstantools config |
We could add a flag, but if rstantools is already massaging the generated C++ it might make the most sense for the change to live there |
Sounds good to me, especially if it's only relevant for CRAN packages |
I've recently been compiling a bunch of Stan models with
-Wall
and noticed this will often lead to a lot of unused variable warnings. We've handled most of the ones of compiler-generated variables already, mostly using the(void) variable_name;
trick, but if the user's code features variables which are unused (or unused in certain contexts, like atransformed parameter
which is used ingenerated quantities
but notmodel
), this leads to warnings during C++ compilation.This PR explores an alternative which is to generate
#pragma diagnostic ignore
directives for unused variable warnings, so they will be disabled in the model's code regardless of the global warning setting.This has the advantage of not requiring those void casts everywhere and working for users' model variables, but has the downside that it is probably not as portable, users with other compilers would see more warnings after this.
Submission Checklist
Release notes
The C++ code generated from stanc3 should provoke fewer unused variable warnings when compiled.
Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)