Description
Describe the bug
When compiling the regression-tests with a high warning level there are warnings in cpp2util.h
as well as in some of the generated C++ code that cppfront produces.
To Reproduce
- Edit the
regression-tests\test-results\msvc-2022\run-tests-msvc-2022.bat
file - Add
-W4
to thecl.exe
command on line 19 - Run the
run-tests-msvc-2022.bat
file
I only did so for MSVC but I imagine adding -Wall
etc to the scripts for Clang & GCC will show similar warnings.
Warnings in cpp2util.h
See the mixed-inspect-values.cpp.output
file for some good examples.
Warnings about conversions and unreachable code
mixed-inspect-values.cpp
..\..\..\include\cpp2util.h(1376): warning C4244: 'argument': conversion from 'const _First' to 'int', possible loss of data
with
[
_First=double
]
..\..\..\include\cpp2util.h(1376): note: the template instantiation context (the oldest one first) is
mixed-inspect-values.cpp2(10): note: see reference to function template instantiation 'void test<std::variant<double,std::string,double>>(const _T0 &)' being compiled
with
[
_T0=std::variant<double,std::string,double>
]
mixed-inspect-values.cpp2(35): note: see reference to function template instantiation 'bool cpp2::is<double,std::string,double,in::<lambda_1>>(const std::variant<double,std::string,double> &,_T0 &&)' being compiled
with
[
_T0=in::<lambda_1>
]
..\..\..\include\cpp2util.h(1178): warning C4244: 'argument': conversion from 'const _T0' to 'int', possible loss of data
with
[
_T0=double
]
..\..\..\include\cpp2util.h(1178): note: the template instantiation context (the oldest one first) is
mixed-inspect-values.cpp2(28): note: see reference to function template instantiation 'void test<double>(const _T0 &)' being compiled
with
[
_T0=double
]
mixed-inspect-values.cpp2(35): note: see reference to function template instantiation 'bool cpp2::is<_T0,in::<lambda_1>>(const _T0 &,_T1 &&)' being compiled
with
[
_T0=double,
_T1=in::<lambda_1>
]
cpp2util.h(1616) : warning C4702: unreachable code
cpp2util.h(1188) : warning C4702: unreachable code
cpp2util.h(1570) : warning C4702: unreachable code
Some of the unreachable code
warnings are fixed by PR #971
Warnings in generated C++ code
Here are the MSVC output files containing compiler warnings
mixed-captures-in-expressions-and-postconditions.cpp.output
mixed-inspect-values-2.cpp.output
mixed-inspect-values.cpp.output
mixed-intro-example-three-loops.cpp.output
mixed-postexpression-with-capture.cpp.output
pure2-bugfix-for-unbraced-function-expression.cpp.output
pure2-bugfix-for-variable-template.cpp.output
pure2-enum.cpp.output
pure2-inspect-generic-void-empty-with-variant-any-optional.cpp.output
pure2-last-use.cpp.output
pure2-more-wildcards.cpp.output
pure2-print.cpp.output
pure2-requires-clauses.cpp.output
pure2-stdio.cpp.output
The warnings include things like:
warning C4389: '==': signed/unsigned mismatch
warning C4211: nonstandard extension used: redefined extern to static
warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead.
warning C4189: 'auto_1': local variable is initialized but not referenced
Some of them may be expected (e.g. using fopen
) but others may warrant some investigation. The warning about auto_1
will be fixed by PR #969.
The redefined extern to static
warning relates to this:
pure2-requires-clauses.cpp2
line 20:
v: <T> const T requires std::same_as<T, i32> = 0;
Lowered to:
template<typename T>
CPP2_REQUIRES_ (std::same_as<T,cpp2::i32>) extern T const v;